popen

Popen printing weird whitespace

Popen printing weird whitespace Question: I am trying to run ssh using subprocess.Popen. It works, but keeps printing some weird whitespace. As the time goes on, whitespace increases Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi Hi And my code was from subprocess import Popen, DEVNULL …

Total answers: 1

Prevent Popen from freezing when waiting for input

Prevent Popen from freezing when waiting for input Question: What: I am creating a custom console for an application I am making that has to handle processes (I/O) and its UI. Why: I am using Tkinter as the UI library. This needs an active main loop in order not to hang. When the Popen process …

Total answers: 1

os.popen strange codec issue

os.popen strange codec issue Question: So im trying to use os.popen to run cmd comands, but the problem is that most of the comands have cyrillic characters in them that seem to have some issues with os.popen. When i use this code import os stream = os.popen("dir") output = stream.read() print(output) I get output like …

Total answers: 1

How do I run a PowerShell script with parameters from Python

How do I run a PowerShell script with parameters from Python Question: I’m trying to run PowerShell scripts that have parameters from Python 3.7.3, but don’t know how to properly call the function in Popen What I’m trying to do with my PowerShell script is login to Cisco routers and run Cisco IOS commands on …

Total answers: 1

Capture output as a tty in python

Capture output as a tty in python Question: I have a executable which requires a tty (as stdin and stderr), and want to be able to test it. I want to input stdin, and capture the output of stdout and stderr, here’s an example script: # test.py import sys print(“stdin: {}”.format(sys.stdin.isatty())) print(“stdout: {}”.format(sys.stdout.isatty())) print(“stderr: {}”.format(sys.stderr.isatty())) …

Total answers: 1

Why python subprocess.Popen need close_fds parameter?

Why python subprocess.Popen need close_fds parameter? Question: Creating a subprocess seems to need to close some fd from caller, e.g., if caller opened fd 0,1,2(stdin,out,err) and fd=3(file named “a.txt”), and subprocess.Popen sets “close_fd=True”, like p=subprocess.Popen(cmd,shell=True,close_fds=True,stdout=None… Does it mean: (1) fd 0-3 are closed in subprocess? (2) if fd 0-3 are closed, how could subprocess print …

Total answers: 1

Tilde (~) isn't working in subprocess.Popen()

Tilde (~) isn't working in subprocess.Popen() Question: When I run in my Ubuntu terminal: sudo dd if=/dev/sda of=~/file bs=8k count=200k; rm -f ~/file it works fine. If I run it through Pythons subprocess.Popen(): output, err = subprocess.Popen([‘sudo’, ‘dd’, ‘if=/dev/’ + disk, ‘of=~/disk_benchmark_file’, ‘bs=8k’, ‘count=200k’], stderr=subprocess.PIPE).communicate() print err it doesn’t work. The Error I get is: …

Total answers: 4

Passing command line argument to subprocess module

Passing command line argument to subprocess module Question: I have a Python script which calls Perl script using subprocess module. In terminal I run the Perl script like this: perl email.pl [email protected] I am passing in "[email protected]" as command line argument to that script. This is my Python script: import subprocess pipe = subprocess.Popen(["perl","./email.pl"]) print …

Total answers: 1

Python popen() – communicate( str.encode(encoding="utf-8", errors="ignore") ) crashes

Python popen() – communicate( str.encode(encoding="utf-8", errors="ignore") ) crashes Question: Using Python 3.4.3 on Windows. My script runs a little java program in console, and should get the ouput: import subprocess p1 = subprocess.Popen([ … ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) out, err = p1.communicate(str.encode(“utf-8”)) This leads to a normal ‘UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in …

Total answers: 3

subprocess.Popen() error (No such file or directory) when calling command with arguments as a string

subprocess.Popen() error (No such file or directory) when calling command with arguments as a string Question: I am trying to count the number of lines in a file using Python functions. Within the current directory, while os.system(“ls”) finds the file, the command subprocess.Popen([“wc -l filename”], stdout=subprocess.PIPE) does not work. Here is my code: >>> import …

Total answers: 2