subprocess

How to get a list of a repository branches using Python

爷,独闯天下 提交于 2021-02-10 06:37:14
问题 I am trying to get a list of all the branches available on my repository using Python with this code : import subprocess branches = ["All"] command = "git branch -r" branch_list = subprocess.check_output(command) for branch in branch_list: print branch branches.append[branch] What I want is to have something like : print branches[0] # is "All" print branches[1] # is "branch1" print branches[2] # is "branch2" etc etc but instead of that I have print branches[0] # is "All" print branches[1] #

Difference between shell=True or False in python subprocess [duplicate]

百般思念 提交于 2021-02-09 14:36:33
问题 This question already has answers here : Actual meaning of 'shell=True' in subprocess (6 answers) Closed 4 years ago . I just started working with python subprocess module. The code subprocess.call("ls", shell = False) and subprocess.call("ls", shell = True) both return the same results. I just want to know what is the main difference between the two shell options. 回答1: Straight out of the Docs: If shell is True, the specified command will be executed through the shell. This can be useful if

Generator from function prints

蓝咒 提交于 2021-02-09 11:54:08
问题 At the moment I have a little flask project that calls another python file. I'm fully aware that this way is kinda awful, and so, I want to swap it for a function call while maintaining the prints getting yelded to the website . def get_Checks(): root = request.url_root def func(): yield ("Inicio <br>") with subprocess.Popen(r"python somefile.py", stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: for line in p.stdout: yield (line + "<br>") return Response(func()) I've tryed to

python subprocess won't interleave stderr and stdout as what terminal does

瘦欲@ 提交于 2021-02-08 21:24:54
问题 A test program #!/usr/bin/env python3 import sys count = 0 sys.stderr.write('stderr, order %d\n' % count) count += 1 sys.stdout.write('stdout, order %d\n' % count) count += 1 sys.stderr.write('stderr, order %d\n' % count) count += 1 sys.stdout.write('stdout, order %d\n' % count) when invoked through the terminal, the expected output is, stderr, order 0 stdout, order 1 stderr, order 2 stdout, order 3 In the interactive shell, when I redirect stdout to a PIPE, the output order is different from

python subprocess won't interleave stderr and stdout as what terminal does

£可爱£侵袭症+ 提交于 2021-02-08 21:24:22
问题 A test program #!/usr/bin/env python3 import sys count = 0 sys.stderr.write('stderr, order %d\n' % count) count += 1 sys.stdout.write('stdout, order %d\n' % count) count += 1 sys.stderr.write('stderr, order %d\n' % count) count += 1 sys.stdout.write('stdout, order %d\n' % count) when invoked through the terminal, the expected output is, stderr, order 0 stdout, order 1 stderr, order 2 stdout, order 3 In the interactive shell, when I redirect stdout to a PIPE, the output order is different from

Why does communicate deadlock when used with multiple Popen subprocesses?

我的未来我决定 提交于 2021-02-08 12:53:08
问题 The following issue does not occur in Python 2.7.3. However, it occurs with both Python 2.7.1 and Python 2.6 on my machine (64-bit Mac OSX 10.7.3). This is code I will eventually distribute, so I would like to know if there is any way to complete this task that does not depend so dramatically on the Python version. I need to open multiple subprocesses in parallel and write STDIN data to each of them. Normally I would do this using the Popen.communicate method. However, communicate is

Python: Subprocess “call” function can't find path

[亡魂溺海] 提交于 2021-02-08 11:31:25
问题 I have a python program that needs to run a bash command on a server. The program works when I run a bash command in my local directory like this: import subprocess from subprocess import call call(['bash', 'Script_Test.sh']) However, after SSH'ing to a server and running a similar line of code below with a path on the server to a bash script, I get the error "No such file or directory" call['bash', path] This doesn't make sense for a number of reasons. I triple checked that the path is

how to keep subprocess running after program exit in golang?

一世执手 提交于 2021-02-08 09:11:21
问题 i noticed that subprocesses created using Start() will be terminated after program exit, for example: package main import "os/exec" func main() { cmd := exec.Command("sh", "test.sh") cmd.Start() } when main() exits, test.sh will stop running 回答1: The subprocess should continue to run after your process ends, as long as it ends cleanly, which won't happen if you hit ^C . What you can do is intercept the signals sent to your process so you can end cleanly. sigchan := make(chan os.Signal, 1)

Combine mp4 files by order based on number from filenames in Python

戏子无情 提交于 2021-02-08 08:24:45
问题 I try to merge lots of mp4 files from a directory test into one output.mp4 using ffmpeg in Python. path = '/Users/x/Documents/test' import os for filename in os.listdir(path): if filename.endswith(".mp4"): print(filename) Output: 4. 04-unix,minix,Linux.mp4 6. 05-Linux.mp4 7. 06-ls.mp4 5. 04-unix.mp4 9. 08-command.mp4 1. 01-intro.mp4 3. 03-os.mp4 8. 07-minux.mp4 2. 02-os.mp4 10. 09-help.mp4 I have tried with the solution below from the reference here: ffmpy concatenate multiple files with a

Run consecutive Shell commands in Python-Subprocess

﹥>﹥吖頭↗ 提交于 2021-02-08 08:23:20
问题 These are some dependant commands i am trying to run. My expectation was it will change current folder to abc & list files. Also after setting z=88 , it will print z . import subprocess cmd_list = [] cmd_list.append("cd ./abc") cmd_list.append("ls") cmd_list.append("export z=88") cmd_list.append("echo $z") my_env = os.environ.copy() for cmd in cmd_list: sp = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=my_env, shell=True,text=True) But