[sage-support] Re: subprocess in SAGE
Thanks for the suggestion. It turned out (for a rather convoluted reason) that the program that I thought I'd be running didn't exist. My bad :-). Victor On Apr 22, 2:58 pm, Jason Grout jason-s...@creativetrax.com wrote: On 04/22/2010 12:18 PM, VictorMiller wrote: I tried using sage -python It still bombs out, but slightly differently: it now does a raise child_exception in the _execute_child method of subprocess, and gets the error string OSError: [Errno 2] No such file or directory On Apr 22, 12:58 pm, Jason Groutjason-s...@creativetrax.com wrote: On 04/22/2010 11:38 AM, VictorMiller wrote: I have some old Python programs that I've been using, and would like to use them as part of SAGE. One particular function I have uses the standard python module subprocess to call an external program, and then process the output from that. This has worked fine in python for a number of years (through various python version changes). However, when I try to use it from within SAGE, when subprocess is finished with the process and it tries to close the process handle it gets an error OSError: [Errno 2] No such file or directory. [Actually I'm not sure if it's even able to spawn the process at all] My guess is that your process can't find your executable. Try doing this (which will check that subprocess works and also check that your executable is found: import subprocess p=subprocess.Popen(/bin/sh,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) output=p.communicate('which ls\n') print output[0], output[1] Replace the which ls command with which YOUR PROGRAM to just double-check that the spawned shell can see your program. The above works for me in Sage, so I think subprocess works just fine in Sage. Thanks, Jason -- Jason Grout -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/sage-support URL:http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: subprocess in SAGE
On 04/22/2010 11:38 AM, VictorMiller wrote: I have some old Python programs that I've been using, and would like to use them as part of SAGE. One particular function I have uses the standard python module subprocess to call an external program, and then process the output from that. This has worked fine in python for a number of years (through various python version changes). However, when I try to use it from within SAGE, when subprocess is finished with the process and it tries to close the process handle it gets an error OSError: [Errno 2] No such file or directory. [Actually I'm not sure if it's even able to spawn the process at all] Is there a known issue with using subprocess from within SAGE? What if you invoke them using sage -python? That will just launch the Sage's version of python, and will narrow down the problem to being (possibly) just a problem with python 2.6.4 (the version that comes with Sage). Thanks, Jason -- Jason Grout -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: subprocess in SAGE
I tried using sage -python It still bombs out, but slightly differently: it now does a raise child_exception in the _execute_child method of subprocess, and gets the error string OSError: [Errno 2] No such file or directory On Apr 22, 12:58 pm, Jason Grout jason-s...@creativetrax.com wrote: On 04/22/2010 11:38 AM, VictorMiller wrote: I have some old Python programs that I've been using, and would like to use them as part of SAGE. One particular function I have uses the standard python module subprocess to call an external program, and then process the output from that. This has worked fine in python for a number of years (through various python version changes). However, when I try to use it from within SAGE, when subprocess is finished with the process and it tries to close the process handle it gets an error OSError: [Errno 2] No such file or directory. [Actually I'm not sure if it's even able to spawn the process at all] Is there a known issue with using subprocess from within SAGE? What if you invoke them using sage -python? That will just launch the Sage's version of python, and will narrow down the problem to being (possibly) just a problem with python 2.6.4 (the version that comes with Sage). Thanks, Jason -- Jason Grout -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/sage-support URL:http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: subprocess in SAGE
I should say that my call is subprocess.Popen(myargs,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) where myargs is the usual list of tokens in the command On Apr 22, 12:58 pm, Jason Grout jason-s...@creativetrax.com wrote: On 04/22/2010 11:38 AM, VictorMiller wrote: I have some old Python programs that I've been using, and would like to use them as part of SAGE. One particular function I have uses the standard python module subprocess to call an external program, and then process the output from that. This has worked fine in python for a number of years (through various python version changes). However, when I try to use it from within SAGE, when subprocess is finished with the process and it tries to close the process handle it gets an error OSError: [Errno 2] No such file or directory. [Actually I'm not sure if it's even able to spawn the process at all] Is there a known issue with using subprocess from within SAGE? What if you invoke them using sage -python? That will just launch the Sage's version of python, and will narrow down the problem to being (possibly) just a problem with python 2.6.4 (the version that comes with Sage). Thanks, Jason -- Jason Grout -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/sage-support URL:http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: subprocess in SAGE
Also, I'm running on Redhat Linux On Apr 22, 1:18 pm, VictorMiller victorsmil...@gmail.com wrote: I tried using sage -python It still bombs out, but slightly differently: it now does a raise child_exception in the _execute_child method of subprocess, and gets the error string OSError: [Errno 2] No such file or directory On Apr 22, 12:58 pm, Jason Grout jason-s...@creativetrax.com wrote: On 04/22/2010 11:38 AM, VictorMiller wrote: I have some old Python programs that I've been using, and would like to use them as part of SAGE. One particular function I have uses the standard python module subprocess to call an external program, and then process the output from that. This has worked fine in python for a number of years (through various python version changes). However, when I try to use it from within SAGE, when subprocess is finished with the process and it tries to close the process handle it gets an error OSError: [Errno 2] No such file or directory. [Actually I'm not sure if it's even able to spawn the process at all] Is there a known issue with using subprocess from within SAGE? What if you invoke them using sage -python? That will just launch the Sage's version of python, and will narrow down the problem to being (possibly) just a problem with python 2.6.4 (the version that comes with Sage). Thanks, Jason -- Jason Grout -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/sage-support URL:http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group athttp://groups.google.com/group/sage-support URL:http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: subprocess in SAGE
I find that it sometimes helps to add shell=True to a call to subprocess.Popen. (I'm not sure why, but you could try that.) On Apr 22, 10:21 am, VictorMiller victorsmil...@gmail.com wrote: I should say that my call is subprocess.Popen(myargs,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr =subprocess.STDOUT) where myargs is the usual list of tokens in the command -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: subprocess in SAGE
On 04/22/2010 12:18 PM, VictorMiller wrote: I tried using sage -python It still bombs out, but slightly differently: it now does a raise child_exception in the _execute_child method of subprocess, and gets the error string OSError: [Errno 2] No such file or directory On Apr 22, 12:58 pm, Jason Groutjason-s...@creativetrax.com wrote: On 04/22/2010 11:38 AM, VictorMiller wrote: I have some old Python programs that I've been using, and would like to use them as part of SAGE. One particular function I have uses the standard python module subprocess to call an external program, and then process the output from that. This has worked fine in python for a number of years (through various python version changes). However, when I try to use it from within SAGE, when subprocess is finished with the process and it tries to close the process handle it gets an error OSError: [Errno 2] No such file or directory. [Actually I'm not sure if it's even able to spawn the process at all] My guess is that your process can't find your executable. Try doing this (which will check that subprocess works and also check that your executable is found: import subprocess p=subprocess.Popen(/bin/sh,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) output=p.communicate('which ls\n') print output[0], output[1] Replace the which ls command with which YOUR PROGRAM to just double-check that the spawned shell can see your program. The above works for me in Sage, so I think subprocess works just fine in Sage. Thanks, Jason -- Jason Grout -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org