subprocess

How to use the subprocess Popen.communicate() method?

回眸只為那壹抹淺笑 提交于 2020-12-12 04:46:39
问题 I'm trying to get the standard output of a bash command as a string in Python. Following Popen documentation, I've tried: import subprocess p = subprocess.Popen(["echo", "hello"]) stdoutdata, stderrdata = p.communicate() print stdoutdata Running this script yields the following output: hello None [Finished in 0.0s] So although the output is getting printed by Python, the stdoutdata variable is None , and not "hello" as I would like. How can I make it so? 回答1: You're not providing any stdout

How to use the subprocess Popen.communicate() method?

≡放荡痞女 提交于 2020-12-12 04:45:32
问题 I'm trying to get the standard output of a bash command as a string in Python. Following Popen documentation, I've tried: import subprocess p = subprocess.Popen(["echo", "hello"]) stdoutdata, stderrdata = p.communicate() print stdoutdata Running this script yields the following output: hello None [Finished in 0.0s] So although the output is getting printed by Python, the stdoutdata variable is None , and not "hello" as I would like. How can I make it so? 回答1: You're not providing any stdout

Python 3 subprocess module throws error running “dir” on Windows

99封情书 提交于 2020-11-28 02:49:50
问题 This simple program in Python 3 throws errors. What could be the reason? This problem arose after I installed/reinstalled Python 3.5/3.6 . Also Python 2.7 is installed on my PC (windows 10 machine). import subprocess out = subprocess.check_output(['dir']) The error message: File "C:\Python36\lib\subprocess.py", line 336, in check_output **kwargs).stdout File "C:\Python36\lib\subprocess.py", line 403, in run with Popen(*popenargs, **kwargs) as process: File "C:\Python36\lib\subprocess.py",

Python 3 subprocess module throws error running “dir” on Windows

本秂侑毒 提交于 2020-11-28 02:45:29
问题 This simple program in Python 3 throws errors. What could be the reason? This problem arose after I installed/reinstalled Python 3.5/3.6 . Also Python 2.7 is installed on my PC (windows 10 machine). import subprocess out = subprocess.check_output(['dir']) The error message: File "C:\Python36\lib\subprocess.py", line 336, in check_output **kwargs).stdout File "C:\Python36\lib\subprocess.py", line 403, in run with Popen(*popenargs, **kwargs) as process: File "C:\Python36\lib\subprocess.py",

Weird subprocess issue with Django

北慕城南 提交于 2020-11-27 04:32:34
问题 I'm sorry if this is a duplicate question, but after searching through 3 pages for "django subprocess", I, for one, could not find the answer to my particular problem. I'm trying to run pdflatex on tex file, but for some reason in Django it doesn't produce anything. It works just fine in a regular python script, though. I've omitted most of the code here, but this is basically the important bit. I'm running this on apache2 with mod_wsgi, and I suspect that it might be an apache permissions

Weird subprocess issue with Django

≡放荡痞女 提交于 2020-11-27 04:31:21
问题 I'm sorry if this is a duplicate question, but after searching through 3 pages for "django subprocess", I, for one, could not find the answer to my particular problem. I'm trying to run pdflatex on tex file, but for some reason in Django it doesn't produce anything. It works just fine in a regular python script, though. I've omitted most of the code here, but this is basically the important bit. I'm running this on apache2 with mod_wsgi, and I suspect that it might be an apache permissions

Weird subprocess issue with Django

微笑、不失礼 提交于 2020-11-27 04:29:25
问题 I'm sorry if this is a duplicate question, but after searching through 3 pages for "django subprocess", I, for one, could not find the answer to my particular problem. I'm trying to run pdflatex on tex file, but for some reason in Django it doesn't produce anything. It works just fine in a regular python script, though. I've omitted most of the code here, but this is basically the important bit. I'm running this on apache2 with mod_wsgi, and I suspect that it might be an apache permissions