os.system()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rami823
    New Member
    • Sep 2008
    • 5

    os.system()

    Hi,
    I am tryting to invoke an application that is located at:
    "P:\P_NS0\tools \tpprogV27k.exe "

    I am only using the following the following code:

    import os
    os.system("P:\P _NS0\tools\tppr ogV27k.exe");

    I get the following error:
    'P:\P_NS0' is not recognized as an internal or external command,
    operable program or batch file.

    If I type the same code in PythonWin I get the following:

    >>> os.system("P:\P _NS0\tools\tppr ogV27k.exe");
    1

    Please help me I am a new pyhton user any help is greatly appreciated.
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    Hi,
    Do you know about escape sequences? If a character in a string has a backslash in front of it, it and the backslash are treated as one special character. I think this may be the source of your problem. If you put two backslashes in a row, they are treated as a single backslash. Try that and see if it helps.
    Good luck.

    Comment

    • rami823
      New Member
      • Sep 2008
      • 5

      #3
      Originally posted by boxfish
      Hi,
      Do you know about escape sequences? If a character in a string has a backslash in front of it, it and the backslash are treated as one special character. I think this may be the source of your problem. If you put two backslashes in a row, they are treated as a single backslash. Try that and see if it helps.
      Good luck.
      Thanks for the help,
      I tried the following and I got these:


      >>> os.system("c:/")
      1
      >>> os.system("c:/")
      1
      >>> os.system("P:/")
      1
      >>> os.system("c:")
      0
      >>> os.system("P:")

      but neither C: nor P: drive opened

      Comment

      • boxfish
        Recognized Expert Contributor
        • Mar 2008
        • 469

        #4
        If you're using windows, and you want to open those drives with Windows Explorer, use the explorer command:
        Code:
        os.system("explorer \"c:\\\")
        (the backslashes before the quotes differentiate them from the end of the string).

        If you want to change the active directory to one of those drives, use the chdir function:
        Code:
        os.chdir("c:\\")
        Or are you trying to do something else?

        Comment

        • shreyask
          New Member
          • Sep 2008
          • 8

          #5
          have you tried this -

          >>os.system(r"P:\P_NS0\tools \tpprogV27k.exe ");

          in case you missed the change, there is an extra 'r' (meaning raw), before specifying the string.

          -
          shreyas

          Comment

          • rami823
            New Member
            • Sep 2008
            • 5

            #6
            Originally posted by shreyask
            have you tried this -

            >>os.system(r"P:\P_NS0\tools \tpprogV27k.exe ");

            in case you missed the change, there is an extra 'r' (meaning raw), before specifying the string.

            -
            shreyas
            Thank you shreyas it worked :)

            Comment

            • rami823
              New Member
              • Sep 2008
              • 5

              #7
              Originally posted by rami823
              Thank you shreyas it worked :)

              hi,
              I have now another problem,
              I am opening two programs using two

              os.system() commands but the problem is that the second program does not open unless I close the first one.
              It does not matter which program comes first

              thank you all for the support
              Ram

              Comment

              • Laharl
                Recognized Expert Contributor
                • Sep 2007
                • 849

                #8
                Right. System() does not return to Python until after the program run with it exits. If you want it to run separately, look up the os.exec family of functions after creating a separate process with os.fork().

                Documentation for both can be found on the Internet, but will most likely refer to the C versions these are wrappers for.

                Comment

                • rami823
                  New Member
                  • Sep 2008
                  • 5

                  #9
                  Originally posted by Laharl
                  Right. System() does not return to Python until after the program run with it exits. If you want it to run separately, look up the os.exec family of functions after creating a separate process with os.fork().

                  Documentation for both can be found on the Internet, but will most likely refer to the C versions these are wrappers for.

                  I learned from little research that the function os.fork() does not work on microsoft windows and it only works on linux.

                  Comment

                  • Laharl
                    Recognized Expert Contributor
                    • Sep 2007
                    • 849

                    #10
                    That is likely because the C version is a *nix system call...I figured the Python guys would have set up a wrapper to a similar Windows system call, CreateProcess. You've reached the end of my knowledge of Windows-specific Python, I'm afraid...

                    Comment

                    Working...