Results 1 to 6 of 6

Thread: Python help:Windows commands with python

  1. #1
    Join Date
    Jul 2007
    Location
    /earth/USA/WA/Spokane
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Python help:Windows commands with python

    This is the script I'm trying to use
    Code:
    import os
    selection = raw_input("Press one to enable two disable the screen saver")
    elif selection == 1:
        os.system(nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 1)
    if selection == 2:
        os.system(nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 0)
    It's says there's an invalid syntax with "regsetval" how do i make sure it's seeing the whole thing as one command rather then separate ones?
    Ubuntu User # 17031
    Quote Originally Posted by RAV TUX View Post
    who needs support when you use Linux.
    Quote Originally Posted by asjdfwejqrfjcvm msz34rq33 View Post
    Open-Source: The power to create completely useless, but extremely cool, programs.

  2. #2
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Python help:Windows commands with python

    http://docs.python.org/library/os.html#os.system

    os.system takes a single string as argument, so:

    Code:
    import os
    selection = raw_input("Press one to enable two disable the screen saver")
    elif selection == 1:
        os.system('nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 1')
    if selection == 2:
        os.system('nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 0')
    You might also need to escape the blackslashes.
    Last edited by Bachstelze; August 14th, 2010 at 12:53 AM.
    「明後日の夕方には帰ってるからね。」


  3. #3
    Join Date
    Jul 2007
    Location
    /earth/USA/WA/Spokane
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Python help:Windows commands with python

    Thanks man.
    Ubuntu User # 17031
    Quote Originally Posted by RAV TUX View Post
    who needs support when you use Linux.
    Quote Originally Posted by asjdfwejqrfjcvm msz34rq33 View Post
    Open-Source: The power to create completely useless, but extremely cool, programs.

  4. #4
    Join Date
    Jul 2007
    Location
    /earth/USA/WA/Spokane
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Python help:Windows commands with python

    Now it's saying that it's an invalid syntax at the first colon. Also here's the updated code, I switched from os.system, to subprocess.Popen.
    Code:
    import subprocess
    selection = int(raw_input("Press one to enable and two disable the screen saver: ")
    if selection == 1:
        subprocess.Popen('nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 1')
    elif selection == 2:
        subprocess.Popen('nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 0')
    Last edited by blithen; August 14th, 2010 at 01:15 AM.
    Ubuntu User # 17031
    Quote Originally Posted by RAV TUX View Post
    who needs support when you use Linux.
    Quote Originally Posted by asjdfwejqrfjcvm msz34rq33 View Post
    Open-Source: The power to create completely useless, but extremely cool, programs.

  5. #5
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Python help:Windows commands with python

    Code:
    selection = int(raw_input("Press one to enable and two disable the screen saver: ")
    Two opening parentheses, one closing. An editor with decent syntax highlighting would have helped you catch this.

    subprocess.Popen doesn't work the same way, it takes a list of strings (the command and its arguments). If you want to use it, it's:

    Code:
    subprocess.Popen(['nircmd.exe', 'regsetval', 'sz', 'HKCU\\control panel\\desktop', 'ScreenSaveActive', '1'])
    Or something along those lines, maybe it's a bit different on Windows.
    Last edited by Bachstelze; August 14th, 2010 at 01:38 AM.
    「明後日の夕方には帰ってるからね。」


  6. #6
    Join Date
    Jul 2007
    Location
    /earth/USA/WA/Spokane
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Python help:Windows commands with python

    Oh wow, thanks for the info, and yeah I'm downloading a text editor now that I look like a noob. >_>
    Ubuntu User # 17031
    Quote Originally Posted by RAV TUX View Post
    who needs support when you use Linux.
    Quote Originally Posted by asjdfwejqrfjcvm msz34rq33 View Post
    Open-Source: The power to create completely useless, but extremely cool, programs.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •