![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
os.spawnl not working
I can run the following command in Windows command line successfully (assuming I have cd'ed to the proper directory:
> Reader.exe sig5C "C:\path\to\file.ext" I am trying to run this command from a Python script. What I have so far is below. It launches the program but it quits before it processes the files. What am I doing wrong? fp = r'C:\path\to\file.ext' READER = r'C:\path\to\Reader.exe' os.spawnl(os.P_WAIT, READER, READER, 'sig5C', '"%s"'%fp) |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Not sure how this is with Python so there exists the possibility I'm completely wrong, but shouldn't you use, like in most other programming languages, a double backslash?
|
|
|
|
|
|
#3 | |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,827
Rep Power: 5
![]() |
Quote:
print 'first line\nsecond line' print r'\nsecond line' @OP: The program may not like arguments with forward slashes in them. Try writing a python script that spits out the arguments (sys.argv). Then direct your code to open that script and see what the arguments are translating to within the script. EDIT!! Oh, I totally missed the first thing you said. About it working with those arguments! The third parameter in os.spawnl is where the arguments begin, yet you began 'sig5C' on the fourth parameter. Your code has three additional arguments, when your working example has only two. It seems that you've repeated "READER" excessively. Last edited by Sane; Jul 17th, 2006 at 6:44 PM. |
|
|
|
|
|
|
#4 | ||
|
Expert Programmer
|
Quote:
Quote:
import os
execpath = os.path.abspath('getter.py')
os.spawnl(os.P_WAIT, execpath, 'arg1', 'arg2')Traceback (most recent call last): File "C:\Documents and Settings\jboyle\Desktop\DataView\optargs\poster.py", line 3, in ? os.spawnl(os.P_WAIT, PATH, PATH, 'arg1', 'arg2') File "C:\Python24\Lib\os.py", line 597, in spawnl return spawnv(mode, file, args) OSError: [Errno 8] Exec format error Script terminated. |
||
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 824
Rep Power: 4
![]() |
I think you have to pass READER in twice, as the second READER is argv[0] (in C speak). That seemed to work for me, parameters and all.
It doesn't seem to let you exec python programs, you will need to invoke python.exe and pass it the parameter of the .py program you want to run. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,827
Rep Power: 5
![]() |
Maybe I'm misinterpreting exactly what os.spawnl does. Why not just use os.system, and use the appropriate call with the appropriate arguments?
|
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
|
|
|
|
|
|
#8 |
|
Expert Programmer
|
Thank you, Game_Ender! Popen works!
import subprocess as sub fp = r'C:\path\to\file.ext' READER = r'C:\path\to\Reader.exe' cmd = '%s %s "%s"' % (READER, 'sig5C', fp) p = sub.Popen(cmd) p.wait() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| working example | badbasser98 | C++ | 16 | Mar 31st, 2006 9:29 AM |
| Reading and writing files not working under Windows (find under unix/linux) | .TD | Java | 2 | Mar 30th, 2006 12:42 PM |
| DropDownList in DataGrid not working! | wright45 | ASP | 1 | Jun 19th, 2005 11:46 AM |
| working with xml and c# and get this error | dark_omen | C# | 4 | May 6th, 2005 6:55 AM |
| JSP not working on the live server | Braveheart | Java | 0 | Mar 9th, 2005 8:20 PM |