subprocess

Pyinstaller issue with subprocess.check_output

﹥>﹥吖頭↗ 提交于 2021-02-11 08:06:54
问题 When I have subprocess.check_output function in mycode and I generate an .exe file using pyinstaller with python pyinstaller.py --noconsole -F myprogram.py process stop to work, otherwise every thing is ok! Do you know any solution with pyinstaller or replace subprocess library with some thing else? 来源: https://stackoverflow.com/questions/18613642/pyinstaller-issue-with-subprocess-check-output

import matplotlib failed in Anaconda python3.6

时光总嘲笑我的痴心妄想 提交于 2021-02-10 20:14:10
问题 I installed Anaconda to simplify the management of many python modules. After that i tried to "import subprocess": >>> import subprocess Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sej/.config/anaconda3/lib/python3.6/subprocess.py", line 155, in <module> _PopenSelector = selectors.SelectSelector AttributeError: module 'selectors' has no attribute 'SelectSelector' How to fix this? I came accross this problem by trying to use matplotlib. When trying to

Python : WindowsError: [Error 6] The handle is invalid

吃可爱长大的小学妹 提交于 2021-02-10 16:21:12
问题 I am trying to develop python plugin on QGIS and I am trying to execute binary programs using subprocess : program = os.path.join(self.tranusConf.tranusBinPath,'pasos' + self.extension) if not os.path.isfile(program): logging.error('The <pasos> program was not found in %s'%self.tranusBinPath ) return 0 outpasos = os.path.join(self.resultDirectory, "outpasos.txt") outpasoserr = os.path.join(self.resultDirectory, "outpasoserr.txt") args = [program, self.tranusConf.scenarioId, " "] result =

Python : WindowsError: [Error 6] The handle is invalid

我怕爱的太早我们不能终老 提交于 2021-02-10 16:19:49
问题 I am trying to develop python plugin on QGIS and I am trying to execute binary programs using subprocess : program = os.path.join(self.tranusConf.tranusBinPath,'pasos' + self.extension) if not os.path.isfile(program): logging.error('The <pasos> program was not found in %s'%self.tranusBinPath ) return 0 outpasos = os.path.join(self.resultDirectory, "outpasos.txt") outpasoserr = os.path.join(self.resultDirectory, "outpasoserr.txt") args = [program, self.tranusConf.scenarioId, " "] result =

Print bash history using python

狂风中的少年 提交于 2021-02-10 16:18:55
问题 I have to print bash history using subprocess package. import subprocess co = subprocess.Popen(['history'], stdout = subprocess.PIPE) History = co.stdout.read() print("----------History----------" + "\n" + History) but they prompt an error Traceback (most recent call last): File "test.py", line 4, in <module> co = subprocess.Popen(['history'], stdout = subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 394, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py",

Python parent process is not catching SIGTERM/SIGINT signals when launching subprocess using os.sytem()

亡梦爱人 提交于 2021-02-10 14:38:20
问题 I have two python scripts as below - parent.py import os import signal shutdown = False def sigterm_handler(signum, frame): global shutdown shutdown = True if __name__ == '__main__': signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGINT, sigterm_handler) os.chdir(os.path.dirname(os.path.abspath(__file__))) cmd = 'python child.py' while True: if shutdown == True: break print 'executing %s' % cmd exit_code = os.system(cmd) print 'Exit Code from %s > %s' % (cmd, exit_code)

How to terminate process created by Python Popen

半腔热情 提交于 2021-02-10 14:27:53
问题 I'm running calc.exe (windows 10, python 3.6) using proc = subprocess.Popen("calc.exe") , then time.sleep(time) and then want to kill process: os.kill(proc.pid, -9) or os.kill(proc.pid, signal.SIGTERM) gives me error "Access Denied". I also tried proc.terminate - it didn't help. And I also noticed that proc.pid gives different PID from PID which is shown in task manager. Any ideas how to kill my process? Thanks! 回答1: You can try using windows to kill the process. command = "Taskkill /IM calc

How to terminate process created by Python Popen

倾然丶 夕夏残阳落幕 提交于 2021-02-10 14:27:45
问题 I'm running calc.exe (windows 10, python 3.6) using proc = subprocess.Popen("calc.exe") , then time.sleep(time) and then want to kill process: os.kill(proc.pid, -9) or os.kill(proc.pid, signal.SIGTERM) gives me error "Access Denied". I also tried proc.terminate - it didn't help. And I also noticed that proc.pid gives different PID from PID which is shown in task manager. Any ideas how to kill my process? Thanks! 回答1: You can try using windows to kill the process. command = "Taskkill /IM calc

Python subprocess FileNotFoundError

纵然是瞬间 提交于 2021-02-10 13:43:44
问题 I am trying to follow this blog on how to execute an R script from Python. I have the R script working fine from the command line using Rscript. Here's my Python code: import subprocess import os command = "C:\Program Files\R\R-3.4.4\bin\Rscript" path2script = os.getcwd() + "\max.R" # gives me the absolute path to the R script args = ["11", "3", "9", "42"] cmd = [command, path2script] + args x = subprocess.check_output(cmd, universal_newlines = True) Which gives me this error:

How to chose Paper Format when printing a PDF File with Python?

僤鯓⒐⒋嵵緔 提交于 2021-02-10 08:26:29
问题 I am trying to print out a PDF file, but I do not know how to specify the Page Format. I want to print all of my PDFs in A5 Format. Can someone please help me? # this code works and prints the PDF File, but not in the A5 Format import subprocess printer='MyPrinter' # name of the printer pdffile=r"C:\Desktop\pdf_test\pdfFile.pdf" # path to PDF acroread=r"C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe" # path to Acrobat Reader # print the file cmd='"%s" /N /T "%s" "%s"' %