stdout

Can't get stdout/stderr from (Python) subprocess.check_output()

Deadly 提交于 2019-12-23 22:14:33
问题 I'm trying to get the message from a git add command, to print to a log file later on. import subprocess import os filename = 'test.txt' # Add changes add_cmd = """git add "%s" """ % filename os.system(add_cmd) a = subprocess.check_output(add_cmd, shell=True, stderr=subprocess.STDOUT) The os.system() call shows in screen: fatal: Not a git repository (or any of the parent directories): .git which is correct, since this folder is not a git repo. But the subprocess.check_output() call fails with

Merge stdout and stderr in Popen

三世轮回 提交于 2019-12-23 21:47:54
问题 In Ruby's popen/spawn, how do I merge both STDOUT and STDERR as a single stream wihthout resorting to using >2&1 ? In Python, this would be: >>> import subprocess >>> subprocess.check_output('my_prog args', stderr=subprocess.STDOUT, shell=True) Note the stderr argument. I use Open3 - as I don't want just stdout - but it already separates them into two streams. 回答1: Using the code from your other question, here you go: cmd = 'a_prog --arg ... --arg2 ...' Open3.popen2({"MYVAR" => "a_value"}, "#

Python: selenium-chromedriver error on new browser object

雨燕双飞 提交于 2019-12-23 18:09:54
问题 I am receiving the below error upon opening a new chromedriver object. The tests run successfully, but this error shows up in our UnitTest output and is undesirable. I would like to either resolve the error or hide it, if possible. I feel it is important to mention that this output only shows up when running the script from the Windows terminal, not when run from the Python Console. [0406/170246.792:ERROR:child_thread_impl.cc(762)] Request for unknown Channel-associated interface: ui::mojom:

How to receive pickle via subprocess.Popen

强颜欢笑 提交于 2019-12-23 17:26:12
问题 getPickle.py import pickle import subprocess cmd = ['rsh', 'host1', 'sendPickle.py'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() results = pickle.load(stdout) print results sendPickle.py import pickle import sys to_return = {'a':1, 'b': 2} pickle.dump(to_return, sys.stdout) OUTPUT: File "getPickle" line 10, in <module> results = pickle.load(stdout) AttributeError: 'str' object has no attribute 'readline' What can I do to get

Reliable non blocking reads from subprocess stdout

孤者浪人 提交于 2019-12-23 16:17:07
问题 Note: I have a process that writes one line to stdout ("print("hello")) and waits for raw_input. I run this process with p = subprocess.Popen, then call p.stdout.readline()....this blocks indefinitely. I am setting shell=False...Why can I not read that first output? p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin = subprocess.PIPE) print(p.stdout.readline()) I have seen this thread about non blocking io for subprocess. I am trying to create an

continuously reading from exec.Cmd output

[亡魂溺海] 提交于 2019-12-23 15:47:37
问题 Guys I am trying pick new lines as they come from command output, but always I end up doing it synchronous way (I have to wait until script is finished). I tired to use fsnotify but it is working only with regular files, do you have any idea how it can be done ? package main import ( "fmt" "os/exec" "bytes" "os" ) func main() { cmd := exec.Command("scripts/long_script") output := new(bytes.Buffer) cmd.Stdout = output cmd.Stderr = output if err := cmd.Start(); err != nil{ // after Start

Writing bytes to standard output in a way compatible with both, python2 and python3

与世无争的帅哥 提交于 2019-12-23 15:00:00
问题 I want a function returning a file object with which I can write binary data to standard output. In python2 sys.stdout is such an object. In python3 it is sys.stdout.buffer . What is the most elegant/preferred way to retrieve such an object so that it works for both, the python2 and the python3 interpreter? Is the best way to check for existance of sys.stdout.buffer (probably using the inspect module) and if it exists, return it and if it doesnt, assume we are on python2 and return sys.stdout

Writing to both terminal and file c++

妖精的绣舞 提交于 2019-12-23 13:07:20
问题 I found this question answered for Python, Java, Linux script, but not C++: I'd like to write all outputs of my C++ program to both the terminal and an output file. Using something like this: int main () { freopen ("myfile.txt","w",stdout); cout<< "Let's try this"; fclose (stdout); return 0; } outputs it to only the output file named "myfile.txt", and prevents it from showing on the terminal. How can I make it output to both simultaneously? I use visual studio 2010 express (if that would make

Gradle Exec task and process output

跟風遠走 提交于 2019-12-23 12:26:44
问题 I have a python script which prints some strings and updates it's execution progress in console: if __name__ == '__main__': ... print 'Hello, world!' while page <= pages: ... done = float(page) / pages sys.stdout.write('\r[{0:50s}] {1:.2f}%'.format('#' * int(done * 50), done * 100)) page += 1 print '' When I run it from console like python script.py everything is ok and I can see output and progressbar. I need to run this script as a part of Gradle build, so, I've created a task: task process

python-daemon not logging stdout redirection

為{幸葍}努か 提交于 2019-12-23 12:19:16
问题 I am using python-daemon in my code that has print statements in it. I want to send them to a file so I ran the following: python server.py >> log.out However, nothing goes in log.out . Can anyone tell me what I need to do? Thanks. 回答1: The DaemonContext object allows redirecting stdout/stderr/stdin when you create the object. For example: import os import daemon if __name__ == '__main__': here = os.path.dirname(os.path.abspath(__file__)) out = open('checking_print.log', 'w+') with daemon