Re: subprocess.Popen question
On Tue, 16 Aug 2011 02:03:50 -0500, Danny Wong (dannwong) wrote: > I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. > > CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, > stderr=subprocess.STDOUT) CMD_OUTPUT.wait() with open(PROJECT_LOGFILE,'r') as f: str = f.read() If you're going to be writing it to a file anyhow, reading that file is likely to be faster than the alternatives. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen question
Am 16.08.2011 09:03 schrieb Danny Wong (dannwong): Hi All, I'm executing a command which I want to capture the standard/stderr output into a file (which I have with the code below), but I also want the standard output to go into a variable so I can process the information for the next command. Any ideas? Thanks. CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, stderr=subprocess.STDOUT) This way it won't work - but if you do sp = subprocess.Popen(COMMAND, stdout=subprocess.PIPE, stderr=subprocess.PIPE) you can flexibly work with both of them. But then the two streams can become intermixed. After that, you would have to emulate the select() behaviour of communicate(), but act differently on them. If you get data on stdout, you capture and append to the file, for data on stderr you only append. Maybe this could work for you: def communicate2(self, input): """ input is readable, output is a generator which yields data """ read_set = [] write_set = [] stdout = None # Return stderr = None # Return # Translate newlines, if requested. We cannot let the file # object do the translation: It is based on stdio, which is # impossible to combine with select (unless forcing no # buffering). if self.universal_newlines and hasattr(file, 'newlines'): xlate=lambda s:self._translate_newlines(s) else: xlate=lambda s:s if self.stdin: # Flush stdio buffer. This might block, if the user has # been writing to .stdin in an uncontrolled fashion. self.stdin.flush() if self.stdout: read_set.append(self.stdout) stdout = [] if self.stderr: read_set.append(self.stderr) stderr = [] inpcrsr=0 # der ist neu... rest='' eofseen=False while read_set or write_set: rlist, wlist, xlist = select.select(read_set, write_set, []) if self.stdin in wlist: # When select has indicated that the file is writable, # we can write up to PIPE_BUF bytes without risk # blocking. POSIX defines PIPE_BUF >= 512 #pipebuf=512 pipebuf=os.fpathconf(self.stdin.fileno(),'PC_PIPE_BUF') if not eofseen: buf=input.read(pipebuf-len(rest)) # else it stays '' if not buf: eofseen=True if rest or buf: bytes_written = os.write(self.stdin.fileno(), rest+buf) if bytes_written > len(rest): rest=buf[bytes_written-len(rest):] else: rest=rest[bytes_written:]+buf else: self.stdin.close() write_set.remove(self.stdin) if self.stdout in rlist: data = os.read(self.stdout.fileno(), 1024) if data == "": self.stdout.close() read_set.remove(self.stdout) #stdout.append(data) #yield stdout,data yield 1,xlate(data) if self.stderr in rlist: data = os.read(self.stderr.fileno(), 1024) if data == "": self.stderr.close() read_set.remove(self.stderr) #stderr.append(data) yield 2,xlate(data) self.wait() (Im not sure if it is to 100% correct.) This yields tuples (1, ) for stdout data and tuples (2, ) for stderr data. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen question
On Tue, Aug 16, 2011 at 12:03 AM, Danny Wong (dannwong) wrote: > Hi All, > I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. Pipe it thru `tee`: http://en.wikipedia.org/wiki/Tee_%28command%29 Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen question
Hi All, I'm executing a command which I want to capture the standard/stderr output into a file (which I have with the code below), but I also want the standard output to go into a variable so I can process the information for the next command. Any ideas? Thanks. CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, stderr=subprocess.STDOUT) -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 23, 6:46 am, SPE - Stani's Python Editor <[EMAIL PROTECTED]> wrote: > On Jun 23, 5:35 am, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: > > > > > > > En Fri, 22 Jun 2007 10:08:49 -0300, [EMAIL PROTECTED] > > <[EMAIL PROTECTED]> escribió: > > > > I seemed to have it working sorta when I run it and save the results I > > > am noticing that inspeit spaces correctly but when I save it to a > > > file I can open it in wordpad there is only one line. when I open in > > > up in WinXound (Acsoundeditor) it is double spaced. if I do it in a > > > batch file the output file is spaced correctly.. when I do splitlines > > > it is giving me one charecter down the page as output.. Do I need to > > > do something or can I do something to put an end of line charecter in > > > the output?? > > > Try > > > print repr(your_data) > > > to see exactly what you got. > > > -- > > Gabriel Genellina > > Did you take in account that line endings on Windows are '\r\n' and > not '\n'? > > Stani > --http://pythonide.stani.be- Hide quoted text - > > - Show quoted text - evedently when they converted awk from unix to windows (gawk) they left the formating the same.. python is working corectly then. gawk seems to return the original line and then the changed line unless I redirect it to a file Thanks for the help, at this point it is up to me to go through the different versions of awk to find out how they work with the data... (awke, gawk, mawk, nawk.. exc..) -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 23, 5:35 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 22 Jun 2007 10:08:49 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribió: > > > I seemed to have it working sorta when I run it and save the results I > > am noticing that inspeit spaces correctly but when I save it to a > > file I can open it in wordpad there is only one line. when I open in > > up in WinXound (A csound editor) it is double spaced. if I do it in a > > batch file the output file is spaced correctly.. when I do splitlines > > it is giving me one charecter down the page as output.. Do I need to > > do something or can I do something to put an end of line charecter in > > the output?? > > Try > > print repr(your_data) > > to see exactly what you got. > > -- > Gabriel Genellina Did you take in account that line endings on Windows are '\r\n' and not '\n'? Stani -- http://pythonide.stani.be -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
En Fri, 22 Jun 2007 10:08:49 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > I seemed to have it working sorta when I run it and save the results I > am noticing that in spe it spaces correctly but when I save it to a > file I can open it in wordpad there is only one line. when I open in > up in WinXound (A csound editor) it is double spaced. if I do it in a > batch file the output file is spaced correctly.. when I do splitlines > it is giving me one charecter down the page as output.. Do I need to > do something or can I do something to put an end of line charecter in > the output?? Try print repr(your_data) to see exactly what you got. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 22, 12:10 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 22 Jun 2007 01:05:36 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribió: > > > > > > >> >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", > >> >> >> "outfile=testdat.sco", "i1.sco"] > >> >> >> output = subprocess.Popen(cmd, > >> >> stdout=subprocess.PIPE).communicate()[0] > >> >> >> lines = output.splitlines() > >> >> >> for line in lines: > >> >> >>print line > > >> >> > C:\dex_tracker\pipe1.py > >> >> > Traceback (most recent call last): > >> >> > File "C:\dex_tracker\pipe1.py", line 14, in > >> >> > last_line = subprocess.Popen([cmd], > >> >> > stdout=subprocess.PIPE).communicate()[0] > >> >> > File "C:\Python25\lib\subprocess.py", line 593, in __init__ > >> >> > errread, errwrite) > >> >> > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child > >> >> > startupinfo) > >> >> > WindowsError: [Error 2] The system cannot find the file specified > >> >> > Script terminated. > > >> >> > I can write it out as a batch file and then run it but that is a > >> messy > >> >> > hack.. > > >> >> If cmd is a list of arguments, like the example above, you should use > >> >> subprocess.Popen(cmd,...) (like the example above, too). > > >> > I had cut and pasted the example in to get that error... could it be > >> > a problem with ms windows??? (I am at a library computer befour work > >> > so that ended my testing) > > >> Note the call to subprocess.Popen- is the first argument [cmd] or cmd? > >> What do you get with print repr(cmd)? > >> Do you have gawk installed on that machine too? > > > gawk is installed.. I do fine when I just call gawk I get all the > > options to use with it but the minute I try to use the options with it > > I have problems. I have done it with batch files but then I would > > have to write out a batch file and then run the batch file. seems > > like more work than I should have to do to use options with a command > > line program.. I have done this in other cases with os.startfile and > > other cases and would like to fix it. > > Ok, but please check *what* are the arguments toPopen. If cmd is a *list* > as shown on the first quoted line on this message, you should call > subprocess.Popen(cmd, ...) as shown on the third line on this message, but > your traceback shows that you are usingPopen([cmd], ...) > Can you see the difference? > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - I seemed to have it working sorta when I run it and save the results I am noticing that in spe it spaces correctly but when I save it to a file I can open it in wordpad there is only one line. when I open in up in WinXound (A csound editor) it is double spaced. if I do it in a batch file the output file is spaced correctly.. when I do splitlines it is giving me one charecter down the page as output.. Do I need to do something or can I do something to put an end of line charecter in the output?? -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
En Fri, 22 Jun 2007 01:05:36 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: >> >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", >> >> >> "outfile=testdat.sco", "i1.sco"] >> >> >> output = subprocess.Popen(cmd, >> >> stdout=subprocess.PIPE).communicate()[0] >> >> >> lines = output.splitlines() >> >> >> for line in lines: >> >> >>print line >> >> >> > C:\dex_tracker\pipe1.py >> >> > Traceback (most recent call last): >> >> > File "C:\dex_tracker\pipe1.py", line 14, in >> >> > last_line = subprocess.Popen([cmd], >> >> > stdout=subprocess.PIPE).communicate()[0] >> >> > File "C:\Python25\lib\subprocess.py", line 593, in __init__ >> >> > errread, errwrite) >> >> > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child >> >> > startupinfo) >> >> > WindowsError: [Error 2] The system cannot find the file specified >> >> > Script terminated. >> >> >> > I can write it out as a batch file and then run it but that is a >> messy >> >> > hack.. >> >> >> If cmd is a list of arguments, like the example above, you should use >> >> subprocess.Popen(cmd,...) (like the example above, too). >> >> > I had cut and pasted the example in to get that error... could it be >> > a problem with ms windows??? (I am at a library computer befour work >> > so that ended my testing) >> >> Note the call to subprocess.Popen- is the first argument [cmd] or cmd? >> What do you get with print repr(cmd)? >> Do you have gawk installed on that machine too? > > gawk is installed.. I do fine when I just call gawk I get all the > options to use with it but the minute I try to use the options with it > I have problems. I have done it with batch files but then I would > have to write out a batch file and then run the batch file. seems > like more work than I should have to do to use options with a command > line program.. I have done this in other cases with os.startfile and > other cases and would like to fix it. Ok, but please check *what* are the arguments to Popen. If cmd is a *list* as shown on the first quoted line on this message, you should call subprocess.Popen(cmd, ...) as shown on the third line on this message, but your traceback shows that you are using Popen([cmd], ...) Can you see the difference? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 21, 1:22 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 20 Jun 2007 22:28:06 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribió: > > > > > > > On Jun 20, 7:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > > wrote: > >> En Wed, 20 Jun 2007 20:02:52 -0300, [EMAIL PROTECTED] > >> <[EMAIL PROTECTED]> escribió: > >> > On Jun 20, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > >> > wrote: > > >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", > >> >> "outfile=testdat.sco", "i1.sco"] > >> >> Now, what do you want to do with the output? Printing it line by > >> line? > >> >> output = subprocess.Popen(cmd, > >> stdout=subprocess.PIPE).communicate()[0] > >> >> lines = output.splitlines() > >> >> for line in lines: > >> >>print line > > >> > C:\dex_tracker\pipe1.py > >> > Traceback (most recent call last): > >> > File "C:\dex_tracker\pipe1.py", line 14, in > >> > last_line = subprocess.Popen([cmd], > >> > stdout=subprocess.PIPE).communicate()[0] > >> > File "C:\Python25\lib\subprocess.py", line 593, in __init__ > >> > errread, errwrite) > >> > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child > >> > startupinfo) > >> > WindowsError: [Error 2] The system cannot find the file specified > >> > Script terminated. > > >> > I can write it out as a batch file and then run it but that is a messy > >> > hack.. > > >> If cmd is a list of arguments, like the example above, you should use > >> subprocess.Popen(cmd,...) (like the example above, too). > > > I had cut and pasted the example in to get that error... could it be > > a problem with ms windows??? (I am at a library computer befour work > > so that ended my testing) > > Note the call to subprocess.Popen- is the first argument [cmd] or cmd? > What do you get with print repr(cmd)? > Do you have gawk installed on that machine too? > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - gawk is installed.. I do fine when I just call gawk I get all the options to use with it but the minute I try to use the options with it I have problems. I have done it with batch files but then I would have to write out a batch file and then run the batch file. seems like more work than I should have to do to use options with a command line program.. I have done this in other cases with os.startfile and other cases and would like to fix it. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
En Wed, 20 Jun 2007 22:28:06 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > On Jun 20, 7:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: >> En Wed, 20 Jun 2007 20:02:52 -0300, [EMAIL PROTECTED] >> <[EMAIL PROTECTED]> escribió: >> > On Jun 20, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> >> > wrote: >> >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", >> >> "outfile=testdat.sco", "i1.sco"] >> >> Now, what do you want to do with the output? Printing it line by >> line? >> >> output = subprocess.Popen(cmd, >> stdout=subprocess.PIPE).communicate()[0] >> >> lines = output.splitlines() >> >> for line in lines: >> >>print line >> >> > C:\dex_tracker\pipe1.py >> > Traceback (most recent call last): >> > File "C:\dex_tracker\pipe1.py", line 14, in >> > last_line = subprocess.Popen([cmd], >> > stdout=subprocess.PIPE).communicate()[0] >> > File "C:\Python25\lib\subprocess.py", line 593, in __init__ >> > errread, errwrite) >> > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child >> > startupinfo) >> > WindowsError: [Error 2] The system cannot find the file specified >> > Script terminated. >> >> > I can write it out as a batch file and then run it but that is a messy >> > hack.. >> >> If cmd is a list of arguments, like the example above, you should use >> subprocess.Popen(cmd,...) (like the example above, too). > > I had cut and pasted the example in to get that error... could it be > a problem with ms windows??? (I am at a library computer befour work > so that ended my testing) Note the call to subprocess.Popen - is the first argument [cmd] or cmd? What do you get with print repr(cmd)? Do you have gawk installed on that machine too? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 20, 7:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 20 Jun 2007 20:02:52 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribió: > > > > > > > On Jun 20, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > > wrote: > > >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", > >> "outfile=testdat.sco", "i1.sco"] > >> Now, what do you want to do with the output? Printing it line by line? > >> output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] > >> lines = output.splitlines() > >> for line in lines: > >>print line > > > C:\dex_tracker\pipe1.py > > Traceback (most recent call last): > > File "C:\dex_tracker\pipe1.py", line 14, in > > last_line = subprocess.Popen([cmd], > > stdout=subprocess.PIPE).communicate()[0] > > File "C:\Python25\lib\subprocess.py", line 593, in __init__ > > errread, errwrite) > > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child > > startupinfo) > > WindowsError: [Error 2] The system cannot find the file specified > > Script terminated. > > > I can write it out as a batch file and then run it but that is a messy > > hack.. > > If cmd is a list of arguments, like the example above, you should use > subprocess.Popen(cmd,...) (like the example above, too). > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - I had cut and pasted the example in to get that error... could it be a problem with ms windows??? (I am at a library computer befour work so that ended my testing) -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
En Wed, 20 Jun 2007 20:02:52 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > On Jun 20, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", >> "outfile=testdat.sco", "i1.sco"] >> Now, what do you want to do with the output? Printing it line by line? >> output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] >> lines = output.splitlines() >> for line in lines: >>print line >> > > C:\dex_tracker\pipe1.py > Traceback (most recent call last): > File "C:\dex_tracker\pipe1.py", line 14, in > last_line = subprocess.Popen([cmd], > stdout=subprocess.PIPE).communicate()[0] > File "C:\Python25\lib\subprocess.py", line 593, in __init__ > errread, errwrite) > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child > startupinfo) > WindowsError: [Error 2] The system cannot find the file specified > Script terminated. > > I can write it out as a batch file and then run it but that is a messy > hack.. If cmd is a list of arguments, like the example above, you should use subprocess.Popen(cmd,...) (like the example above, too). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 20, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 20 Jun 2007 12:27:47 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribió: > > > I am trying to modify a programming example and I am coming up with > > two problems... first is that I can't seem to pass along the > > arguments to the external command (I have been able to do that with > > the old module and cmd is the command I wish to try) all the output > > seems to be returned as one line (at least when I run the program in > > spe). > > > import subprocess > > from os import system > > cmd = """gawk -f altertime.awk -v time_offset=4 -v > > outfile="testdat.sco" "i1.sco" """ > > #subprocess.Popen. > > last_line = subprocess.Popen(['gawk.exe'], > > stdout=subprocess.PIPE).communicate()[0] > > You build what appears to be the desired command line, but execute > gawk.exe instead. > Better split the arguments beforehand: > cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", > "outfile=testdat.sco", "i1.sco"] > Now, what do you want to do with the output? Printing it line by line? > output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] > lines = output.splitlines() > for line in lines: >print line > > -- > Gabriel Genellina C:\dex_tracker\pipe1.py Traceback (most recent call last): File "C:\dex_tracker\pipe1.py", line 14, in last_line = subprocess.Popen([cmd], stdout=subprocess.PIPE).communicate()[0] File "C:\Python25\lib\subprocess.py", line 593, in __init__ errread, errwrite) File "C:\Python25\lib\subprocess.py", line 793, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified Script terminated. I can write it out as a batch file and then run it but that is a messy hack.. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
On Jun 20, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 20 Jun 2007 12:27:47 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribió: > > > I am trying to modify a programming example and I am coming up with > > two problems... first is that I can't seem to pass along the > > arguments to the external command (I have been able to do that with > > the old module and cmd is the command I wish to try) all the output > > seems to be returned as one line (at least when I run the program in > > spe). > > > import subprocess > > from os import system > > cmd = """gawk -f altertime.awk -v time_offset=4 -v > > outfile="testdat.sco" "i1.sco" """ > > #subprocess.Popen. > > last_line = subprocess.Popen(['gawk.exe'], > > stdout=subprocess.PIPE).communicate()[0] > > You build what appears to be the desired command line, but execute > gawk.exe instead. > Better split the arguments beforehand: > cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", > "outfile=testdat.sco", "i1.sco"] > Now, what do you want to do with the output? Printing it line by line? > output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] > lines = output.splitlines() > for line in lines: >print line > > -- > Gabriel Genellina I had one test where I had cmd in place of gawk and one everything was in place of gawk.. I haven't tried what you have listed yet (I am getting ready to go to work so may have to wait until tommorow to try it) THanks for the help -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.popen question
En Wed, 20 Jun 2007 12:27:47 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > I am trying to modify a programming example and I am coming up with > two problems... first is that I can't seem to pass along the > arguments to the external command (I have been able to do that with > the old module and cmd is the command I wish to try) all the output > seems to be returned as one line (at least when I run the program in > spe). > > import subprocess > from os import system > cmd = """gawk -f altertime.awk -v time_offset=4 -v > outfile="testdat.sco" "i1.sco" """ > #subprocess.Popen. > last_line = subprocess.Popen(['gawk.exe'], > stdout=subprocess.PIPE).communicate()[0] You build what appears to be the desired command line, but execute gawk.exe instead. Better split the arguments beforehand: cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v", "outfile=testdat.sco", "i1.sco"] Now, what do you want to do with the output? Printing it line by line? output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] lines = output.splitlines() for line in lines: print line -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
subprocess.popen question
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with the old module and cmd is the command I wish to try) all the output seems to be returned as one line (at least when I run the program in spe). import subprocess from os import system cmd = """gawk -f altertime.awk -v time_offset=4 -v outfile="testdat.sco" "i1.sco" """ #subprocess.Popen. last_line = subprocess.Popen(['gawk.exe'], stdout=subprocess.PIPE).communicate()[0] xx = 0 for line in last_line: xx = xx + 1 if xx < 2: print line print str(xx) -- http://mail.python.org/mailman/listinfo/python-list