popen

Python subprocess: How can I pass a text file as input?

Python subprocess: How can I pass a text file as input? Question: I am in charge of updating some old code with Python. I was originally given a batch file to run it in windows as follows: copy .datarandomdata.txt tape20 copy .InputPROGM.INP . progm_64.exe < PROGM.INP > PROGM.OUT The goal is to not use the …

Total answers: 1

Python Popen writing command prompt output to logfile

Python Popen writing command prompt output to logfile Question: Firstly I am running this Python script on Windows. I am trying to open a new command prompt window every time and want to execute a .exe with some arguments. After I execute, I want to copy the command prompt output to a log file. I …

Total answers: 1

Read text from os.Popen that opens new command prompt

Read text from os.Popen that opens new command prompt Question: I am using os.Popen to open a new command prompt window and run a process. How can I read the text within that command prompt. Please help. import os def OpenServers(): os.chdir(coreServerFullPath) process=os.popen("start cmd /K CoreServer.exe -c -s").read() print(process) #Prints nothing This is the output …

Total answers: 1

Exception Handling with subprocess.run in Python

Exception Handling with subprocess.run in Python Question: I am trying to create a function that can run any shell command and return the stdout of that command, without worrying about any exceptions that could be thrown. When testing the code written below with incorrect commands like xyz testing, I get a FileNotFoundError rather that the …

Total answers: 1

Execute terminal command over python

Execute terminal command over python Question: I’m trying to get the hostname where the .py is running, so I used: server = subprocess.Popen(["hostname"]) print(server.stdout) However, I’m getting this return: None HOSTNAME It always prints a None from the subprocess.Popen() and then the hostname at print(server.stdout). Is there a way to fix this? Asked By: null92 …

Total answers: 1

Check certain Popen is running at first (==Checking variable is assigned)

Check certain Popen is running at first (==Checking variable is assigned) Question: I got a running Thread p in a function and trying to check at first, whether it’s already running or not if p wasn’t running it spits reference before the assignment error from subprocess import check_output,Popen from asyncio.subprocess import PIPE from threading import …

Total answers: 1

Subprocess.Popen does not give output

Subprocess.Popen does not give output Question: I have the following code: from subprocess import Popen, PIPE if os.path.isfile(‘../’): cmd = os.path.join(os.getcwd(), ‘../’) proc = Popen(["python3", "-m", cmd], stdout=PIPE, stderr=PIPE) progRunning = True while progRunning: try: output, error = proc.communicate() except KeyboardInterrupt: print("Program Forcequit") progRunning = False proc.kill() print(‘Process finished’) Where ../ is the directory to …

Total answers: 2

Python Ram usage increases after new thread starts

Python Ram usage increases after new thread starts Question: In a True while loop, I’m starting a new Thread which in turn starts a shell Subprocess (python script). Due to other reasons, the python scripts need to be called using the shell subprocess. The subprocess runs for a certain time and then quits. After each …

Total answers: 2