pipe

How to use `subprocess` command with pipes

How to use `subprocess` command with pipes Question: I want to use subprocess.check_output() with ps -A | grep ‘process_name’. I tried various solutions but so far nothing worked. Can someone guide me how to do it? Asked By: zuberuber || Source Answers: To use a pipe with the subprocess module, you have to pass shell=True. …

Total answers: 7

Python – how to execute shell commands with pipe, but without 'shell=True'?

Python – how to execute shell commands with pipe, but without 'shell=True'? Question: I have a case to want to execute the following shell command in Python and get the output, echo This_is_a_testing | grep -c test I could use this python code to execute the above shell command in python, >>> import subprocess >>> …

Total answers: 5

Multiprocessing – Pipe vs Queue

Multiprocessing – Pipe vs Queue Question: What are the fundamental differences between queues and pipes in Python’s multiprocessing package? In what scenarios should one choose one over the other? When is it advantageous to use Pipe()? When is it advantageous to use Queue()? Asked By: Jonathan Livni || Source Answers: Short Summary As of CY2023, …

Total answers: 4

How to get data from command line from within a Python program?

How to get data from command line from within a Python program? Question: I want to run a command line program from within a python script and get the output. How do I get the information that is displayed by foo so that I can use it in my script? For example, I call foo …

Total answers: 6

running a command line containing Pipes and displaying result to STDOUT

running a command line containing Pipes and displaying result to STDOUT Question: How would one call a shell command from Python which contains a pipe and capture the output? Suppose the command was something like: cat file.log | tail -1 The Perl equivalent of what I am trying to do would be something like: my …

Total answers: 6

How do you read from stdin in python from a pipe which has no ending

How do you read from stdin in python from a pipe which has no ending Question: I’ve problem to read from Standard input or pipe in python when the pipe is from a “open” (do not know right name) file. I have as example pipetest.py: import sys import time k = 0 try: for line …

Total answers: 5

Interprocess communication in Python

Interprocess communication in Python Question: What is a good way to communicate between two separate Python runtimes? Thing’s I’ve tried: reading/writing on named pipes e.g. os.mkfifo (feels hacky) dbus services (worked on desktop, but too heavyweight for headless) sockets (seems too low-level; surely there’s a higher level module to use?) My basic requirement is to …

Total answers: 8

How to run " ps cax | grep something " in Python?

How to run " ps cax | grep something " in Python? Question: How do I run a command with a pipe | in it? The subprocess module seems complex… Is there something like output,error = `ps cax | grep something` as in shell script? Asked By: eugene || Source Answers: import subprocess process = …

Total answers: 5

Checking for interactive shell in a Python script

Checking for interactive shell in a Python script Question: I need to determine whether the shell which invoked my Python script was in interactive mode or not. If it was in interactive mode, the program should pipe output to less(1) for easy reading. If not, it should simply print its output to stdout, to allow …

Total answers: 5

Pipe character in Python

Pipe character in Python Question: I see a “pipe” character (|) used in a function call: res = c1.create(go, come, swim, “”, startTime, endTime, “OK”, ax|bx) What is the meaning of the pipe in ax|bx? Asked By: alwbtc || Source Answers: It is a bitwise OR of integers. For example, if one or both of …

Total answers: 6