subprocess

python subprocess.call() doesn't work with multiline shell commands

python subprocess.call() doesn't work with multiline shell commands Question: I would like to run this multiline shell commands: echo ‘a=?’ read a echo "a=$a" from a python script, using the subprocess.call() method. I wrote this, in test.py file: import shlex, subprocess args = ["echo", ‘a=?’,"read", "a", "echo", "a=$a"] subprocess.call(args) and when I execute it, I …

Total answers: 1

Unable to print TCPcump information using python subprocess

Unable to print TCPcump information using python subprocess Question: I wanted to process tcpdump output in a python script and so far I was able to get to this implementation from subprocess import Popen, PIPE, CalledProcessError import os import signal import time if __name__=="__main__": cmd = ["sudo","tcpdump", "-c","1000","-i","any","port","22","-n"] with Popen(cmd, stdout=PIPE, bufsize=1, universal_newlines=True) as p: …

Total answers: 1

UnicodeDecodeError in client server communication when accessing Desktop

UnicodeDecodeError in client server communication when accessing Desktop Question: I want to write a reverse shell like netcat. Everything works fine, but after several commands typed in, the client machine throws an error. I managed to identify the problem. When I change to the Desktop directory on the server, for example C:/Users/Desktop and I type …

Total answers: 1

Unable to hide Chromedriver console with CREATE_NO_WINDOW

Unable to hide Chromedriver console with CREATE_NO_WINDOW Question: Python 3.11 ChromeDriver 107.0.5304.62 Chrome 107.0.5304.107 Selenium 4.6.0 Chromedriver console always shows when I try to build exe with pyinstaller. from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from subprocess import CREATE_NO_WINDOW chrome_options = webdriver.ChromeOptions() chrome_options.binary_location = r’D:Testbinchrome.exe’ chrome_service = ChromeService(r’D:Testbinchromedriver.exe’) chrome_service.creationflags = CREATE_NO_WINDOW driver …

Total answers: 3

Python subprocess run() with multiple arguments on Windows

Python subprocess run() with multiple arguments on Windows Question: I’ve run into a problem trying to start a game with some additional parameters. Normally you enter them in the "target line" on Windows, such as: "C:PathTogame.exe" –arg –arg2 –arg3 abc –arg4 xyz There are both arguments that are simply the argument like –arg and –arg2, …

Total answers: 2

running subprocess with combined cd and pwd

running subprocess with combined cd and pwd Question: I run subprocess in jupyter to get the core path. I have to go one folder up and then call pwd Running: import subprocess mypath=subprocess.run("(cd .. && pwd)") leads to a "No such file or directory: ‘(cd .. && pwd)’ error. I guess the cd calls a …

Total answers: 3

SLURM Array Job BASH scripting within python subprocess

SLURM Array Job BASH scripting within python subprocess Question: Update: I was able to get a variable assignment from SLURM_JOB_ID with this line. JOBID=`echo ${SLURM_JOB_ID}` However, I haven’t yet gotten SLURM_ARRAY_JOB_ID to assign itself to JOBID. Due to needing to support existing HPC workflows. I have a need to pass a bash script within a …

Total answers: 1

How to pass arguments to another .py

How to pass arguments to another .py Question: I’m newbie with python programming and I’m facing an issue with Windows Memory, so I want to understand if the way I’m calling the other "subprogram" ic causing this problem. Basically I’ve done a main program from which I call the other .py (called second_py.py) like this: …

Total answers: 1

Opening powershell from python

Opening powershell from python Question: I would like to open a powershell from my python script, then launch another python script in this newly created powershell. import subprocess subprocess.call("start C:\Windows\System32\WindowsPowerShell\v1.0", shell=True) # Here, I would like to write this in the new opened powershell : python ./hello_world.py (then press ENTER) input("end") Any idea how I …

Total answers: 3