stdin

How to mock stdin when using fileinput module?

How to mock stdin when using fileinput module? Question: I have a program that uses the Python fileinput module, and I am trying to write unittests for the main() function. They work find when using an actual file, but raise OSError: reading from stdin while output is captured when I try to pass data via …

Total answers: 2

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

How to read sys.stdin containing binary data in python (ignore errors)?

How to read sys.stdin containing binary data in python (ignore errors)? Question: How do I read sys.stdin, but ignoring decoding errors? I know that sys.stdin.buffer exists, and I can read the binary data and then decode it with .decode(‘utf8′, errors=’ignore’), but I want to read sys.stdin line by line. Maybe I can somehow reopen the …

Total answers: 2

Count the total number of words from stdin

Count the total number of words from stdin Question: I have to read a text file name (the text file is already on my computer), open it, read it, and print the total number of words. Here is what I’ve tried so far: import sys file = sys.stdin with open(file) as f: # also tried …

Total answers: 2

Execute commands on EC2 using subprocess and aws ssm

Execute commands on EC2 using subprocess and aws ssm Question: I am working with group of EC2 instances that are deployed in a subnet. I usually use the aws ssm command aws ssm start-session –region us-east-2 –target i-01234567abcdef –profile profile-one to connect to that ec2 instance and run commands such as ssh mirrora to go …

Total answers: 1

Stream image from Android with FFMPEG

Stream image from Android with FFMPEG Question: I’m currently receiving images from an external source as byte array and I would like to send it as raw video format via ffmpeg to a stream URL, where I have a RTSP server that receives RTSP streams (a similar unanswered question). However, I haven’t worked with FFMPEG …

Total answers: 2

stdout stdin node to python

stdout stdin node to python Question: I am trying to learn how to pass data back and forth between node and Python using stdin and stdout. This is something super bare bones where the node app.js calls the Python file test.py. app.js const spawn = require("child_process").spawn; const pythonProcess = spawn(‘python3’,["test.py"]); pythonProcess.stdout.on(‘data’, (data) => { mystr …

Total answers: 1

How Postgresql COPY TO STDIN With CSV do on conflic do update?

How Postgresql COPY TO STDIN With CSV do on conflic do update? Question: I want to do ” on conflict (time) do update set name , description ” but I have no idea when I use stdin with csv , I don’t know what name equal what? and description equal what… table_a: xxx.csv: with open(‘xxx/xxx.csv’, …

Total answers: 4

How does Python receive stdin and arguments differently?

How does Python receive stdin and arguments differently? Question: How exactly does Python receive echo input | python script and python script input differently? I know that one comes through stdin and the other is passed as an argument, but what happens differently in the back-end? Asked By: Rohan || Source Answers: I’m not exactly …

Total answers: 1