subprocess

How to use subprocess in Python to run a BASH command that is very complicated (has a lot of redirection and multiple parts)? [duplicate]

天涯浪子 提交于 2021-01-29 20:58:58
问题 This question already has answers here : Bash style process substitution with Python's Popen (1 answer) How to use `subprocess` command with pipes (9 answers) Closed 4 months ago . I am trying to run the following BASH command in Python but I am running into trouble because of all the redirection ("<", ">", "|") and parentheses. "comm -13 <(sort 9-21-pull/animals.tsv | uniq) <(sort full-data/9-28-full-data/animals.tsv | uniq) > 9-28-pull/animals.tsv" How do I run this BASH command in Python

How to use subprocess in Python to run a BASH command that is very complicated (has a lot of redirection and multiple parts)? [duplicate]

删除回忆录丶 提交于 2021-01-29 18:30:21
问题 This question already has answers here : Bash style process substitution with Python's Popen (1 answer) How to use `subprocess` command with pipes (9 answers) Closed 4 months ago . I am trying to run the following BASH command in Python but I am running into trouble because of all the redirection ("<", ">", "|") and parentheses. "comm -13 <(sort 9-21-pull/animals.tsv | uniq) <(sort full-data/9-28-full-data/animals.tsv | uniq) > 9-28-pull/animals.tsv" How do I run this BASH command in Python

Python Google Login User Pass BeautifulSoup Post

你说的曾经没有我的故事 提交于 2021-01-29 09:34:00
问题 I want to login using BeautifulSoup and requests with python. Can you help me? Webdriver ve selenium I can do with but I BeautifulSoup and requests I want to do with from bs4 import BeautifulSoup import json, requests headers = { 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' } url = "https://www.google.com/accounts/Login?hl=tr&continue=http://www.google.com" login_data = { 'id': 'username

Execute command to a Python script from separate Python script?

点点圈 提交于 2021-01-29 07:26:23
问题 I'm trying to send a command from one python script to another running in terminal. I'm running two python scripts on an RPi running Raspbian. The first script is a loop that waits for the user to enter a number and adds it to a total. The second script uses PySide2 to print a number when a QPushButton is released. How can i make it so that the function that runs when the QPushButton is released, sends a command (or variable) into the waiting first script and executes it? I've read some

Java process.waitFor() returns with inconsistent value

假装没事ソ 提交于 2021-01-29 05:46:55
问题 Use process = Runtime.getRuntime.exec("other.sh") to lauch other.sh who exits with 1, however, process.waitFor() returns with 0. Under Linux RedHat 7. other.sh just starts another Java process that returns by System.exit(1) . I've seen the same problem in https://coderanch.com/t/326568/java/exitValue-returns-inconsistent-values. However, it said that this was a JDK bug in 1.4 and was fixed already. However, I am using JDK 1.8. I just want to know if there are any other possibilities leading

Why does `script.py <(cat *.gz)` work with subprocess.Popen in python 2 but not python 3?

一世执手 提交于 2021-01-29 03:20:48
问题 We discovered recently that a script we developed chokes in python 3.x (but not python 2.x) if it is supplied its input files via process substitution, e.g.: script.py <(cat *.gz) We've tested with commands other than gzip, such as cat, just to see if we get a similar error. They all complain that /dev/fd/63 (or /dev/fd/63.gz ) does not exist. Here's the (simplified) relevant bit of code: def open_gzip_in(infile): '''Opens a gzip file for reading, using external gzip if available''' #

subprocess.call() gives “The system cannot find the path specified.” while the file exists and can run that truly

不打扰是莪最后的温柔 提交于 2021-01-28 19:10:14
问题 why running import subprocess # I'm going to run another python script in anaconda script like this: #subprocess.call("C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat && python C:\test.py") # but for simplifying the sample for here I've deleted the second part # (in the case you didn't install python in the default path, you can replace v_activate_address with the correct address on your computer to see the result) v_activate_address = "C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat"

Python subprocess - saving output in a new file

♀尐吖头ヾ 提交于 2021-01-28 11:51:06
问题 I use the following command to reformat a file and it creates a new file: sed -e '1s/^/[/' -e 's/$/,/' -e '$s/,$/]/' toto> toto.json It works fine on the command line. I try to use it through a python script, but it does not create a new file. I try: subprocess.call(["sed", "-e","1s/^/[/","-e", "s/$/,/","-e","$s/,$/]/ ",sys.argv[1], " > ",sys.argv[2]]) The issue is: it gives me the output in the stdout and raise an error: sed: can't read >: No such file or directory Traceback (most recent

accessing python interpreter from a pyinstaller bundle #2

我与影子孤独终老i 提交于 2021-01-28 09:41:07
问题 I'm trying to execute a python script which is included in datas, and bundled into a pyinstaller executable (on a mac). I need to pass parameters to this script, so I can't just exec(open(read()). Outside of pyinstaller, sys.executable is the python interpreter, so calling the python script works fine. In pyinstaller, sys.executable is the 'main' py script, so it just opens up my app again instead of calling the new script. How can I call my additional python script inside my app? This is

Bi-directional inter-process communication using two pipes

为君一笑 提交于 2021-01-28 08:44:22
问题 I am trying to write code that forks a subprocess and communicates with it using pipes. I am using two pipes - one for writing to, and the other for reading from the standard streams of the subprocess. Here's what I have so far: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <string.h> void read_move(int fd) { FILE *stream = fdopen(fd, "r"); char c; setvbuf(stream, NULL, _IONBF, BUFSIZ); while ((c = fgetc(stream)) != EOF) { putchar(c); } fclose(stream)