python | subprocess module| subprocess.Popen| run OS command using subprocess

preview_player
Показать описание
This video will explain about running OS command using subprocess module.
In this module, we are using subprocess.Popen.
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:

 class subprocess.Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, encoding=None, errors=None)

If shell=True, on POSIX the executable argument specifies a replacement shell for the default /bin/sh.

A negative value -N indicates that the child was terminated by signal N (POSIX only).
Рекомендации по теме
Комментарии
Автор

Explained so clearly all aspects of subprocess

deepikapant
Автор

Helped out a lot since the information I was finding elsewhere was outdated. Thanks.

zName
Автор

Awesome video, just got some work-related stuff working thanks to this video.

eassonweisshaar
Автор

Can you run it from inside your IDE and it up the terminal print to the terminal in real time

jhenry
Автор

If in windows, I do:
type logfile | cantools plot inputfile.dbc

What would the syntax look like if I'm trying to do using Popen? The following did not work as it did not pipe the logfile contents to cantools
args = ["plot 1.dbc"]
p = Popen(['cantools'] + args, stdout=PIPE)

bennguyen
Автор

Good video. However, I have read multiple posts regarding the use of this module and almost all of them recommend against using shell=True. What are your thoughts?

ragtop
Автор

Say I wanted to run ssh in a subprocess as a remote shell?

danielgeorge
Автор

And in case if i want to save in a file, the standard out and the error? For example: -c command -f file-out -l log-file . How can i do in that case?

nk_nicolasmayoral
Автор

Could I used this to monitor the breads I make, giving me a live counting list of each loaf I made throughout the day, so I can tell when one of the loaves is ready to cut and serve? Each bread needs to cool for up to 2 hours. So I'd like to be able to keep adding breads to an ever expanding list. That way I can just look at it and tell how long each batch of bread has been cooling. I'm a baker. Thanks

anzwertree
Автор

Nice

Is there any alternate library module to run with python 2.7 version

venkata
Автор

Nice video, but your heading is misleading, I was looking for subprocess.run

PGhai
Автор

How can i read the output of long running process without pausing the program

anuragmishra
Автор

Good night teacher! Would you have any commands to verify that the person ran the application as an administrator?

gesseanedejesusgomes
Автор

please can anyone advise how can I use Atom with auto-completion same as you do..I'm using Atom on MAC OS

RelaxingMusic-dtcr
Автор

Thank you for the explanation!. I have one doubt. Suppose if I want to execute a command with multiple arguments to be passed in the CLI using the Popen subprocess.
For Eg. jira --action createIssue --project "$1" --type "$2" --description $3
I get an error stating that the bufsize must be an integer. But when I provide a valid value for the bufsize argument in Popen. I still get an error stating too many values passed for bufsize argument

pradyumnakatageri
Автор

give example open other then cmd and then process onit.

zahidriaz
Автор

What is the ubuntu version u are using?

hirakhax
Автор

Hi! if I run a bioinformatics pipeline, will this method show the live feed of the pipeline and also capture stderr if something goes wrong in the pipeline? today I have tried using subprocess.run, but if I use the capture_output=True, I wont get any live feed. and if I skip that I will get live feed but I wont get any stderr so I can see what went wrong in case it does:/ pls help!:)

Jonix-redhat
Автор

hey, please how i can rexecute my script python an intern if it's stopped ?

yousen
Автор

Why is every youtube educational video produced out of India such low quality?

amosburton