Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 8th, 2008, 08:36 PM
Newbie
 
Join Date: Sep 2008
Posts: 5
Default 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\tpprogV27k.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\tpprogV27k.exe");
1

Please help me I am a new pyhton user any help is greatly appreciated.
Reply
  #2  
Old September 8th, 2008, 09:41 PM
boxfish's Avatar
Expert
 
Join Date: Mar 2008
Location: ♩♫♬♪♩
Posts: 380
Default

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.
Reply
  #3  
Old September 8th, 2008, 10:29 PM
Newbie
 
Join Date: Sep 2008
Posts: 5
Default

Quote:
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
Reply
  #4  
Old September 9th, 2008, 12:22 AM
boxfish's Avatar
Expert
 
Join Date: Mar 2008
Location: ♩♫♬♪♩
Posts: 380
Default

If you're using windows, and you want to open those drives with Windows Explorer, use the explorer command:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. os.chdir("c:\\")
Or are you trying to do something else?
Reply
  #5  
Old September 9th, 2008, 08:41 AM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default

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
Reply
  #6  
Old September 9th, 2008, 03:55 PM
Newbie
 
Join Date: Sep 2008
Posts: 5
Default

Quote:
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 :)
Reply
  #7  
Old September 9th, 2008, 04:35 PM
Newbie
 
Join Date: Sep 2008
Posts: 5
Default

Quote:
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
Reply
  #8  
Old September 9th, 2008, 09:09 PM
Expert
 
Join Date: Sep 2007
Posts: 846
Default

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.
Reply
  #9  
Old September 11th, 2008, 03:20 PM
Newbie
 
Join Date: Sep 2008
Posts: 5
Default

Quote:
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.
Reply
  #10  
Old September 11th, 2008, 09:17 PM
Expert
 
Join Date: Sep 2007
Posts: 846
Default

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...
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles