stdout

Remove output of all subprocesses in Python without access to code

限于喜欢 提交于 2019-12-11 05:24:28
问题 In Python I'm using sys.stdout = None before some calls that I don't control. These calls may call some subprocesses that write to stdout. How can I avoid this subprocesses calls to write to stdout? Again, I don't have ownership of the code that calls the subprocess. It seems subprocess.Popen (and similar) doesn't honor sys.stdout. 回答1: You could replace subprocess.Popen with a custom function that suppresses stdout and stderr : import subprocess import inspect def Popen(*args, **kwargs): sig

Python: How to print on same line, clearing previous text?

为君一笑 提交于 2019-12-11 05:10:59
问题 In Python you can print on the same line using \r to move back to the start of the line. This works well for progress bars or increasing precentage counters, eg: Python print on same line However when printing lines that may decrease in length, this leaves the previous lines text there, eg: import sys for t in ['long line', '%']: sys.stdout.write(t + '\r') sys.stdout.write('\n') Leaves the terminal text as: %ong line . Whats the best way to write a shorter line after a longer one, when

Is there a way to set a variable up to place output to stdout or null?

夙愿已清 提交于 2019-12-11 04:58:56
问题 I would like to set up a variable in my code that would ultimately define if I'll see some output or not. "hello" writes to stdout "hello" > $null supresses output My idea is something like this: $debugOutputSwitch = $true $outputVar = $null if ($debugOutputSwitch){ $outputVar = **STDOUT** } ... Write-Host "Something I want out anyway" "Something I might not want on STDOUT" > $outputVar If this general idea is a way to go, then STDOUT is what I'm looking for If this idea is completely wrong..

Python: Strange hanging behavior when piping large stdout of a subprocess

非 Y 不嫁゛ 提交于 2019-12-11 04:37:21
问题 I am currently calling ffmpeg to extract a binary data stream from a video file, and then putting that binary data into a list. There is a lot of data in this data stream, about 4,000 kb. Here is the code # write and call ffmpeg command, piping stdout cmd = "ffmpeg -i video.mpg -map 0:1 -c copy -f data -" proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) # read from stdout, byte by byte li = [] for char in iter(lambda: proc.stdout.read(1), ""): li.append(char) This works fine. However, if

Processing jpgs stream from the standard output

为君一笑 提交于 2019-12-11 04:21:36
问题 Using FFmpeg I converted a video (mpeg2) into jpgs, redirecting the output into the standard output. StringBuilder str = new StringBuilder(); //Input file path str.Append(string.Format(" -i {0}", myinputFile)); //Set the frame rate str.Append(string.Format(" -r {0}", myframeRate); //Indicate the output format str.Append(" -f image2pipe"); //Connect the output to the standard output str.Append(" pipe:1"); return str.ToString(); I'm able to receive the callback from the process with the data:

Redirect but also display process output stream

余生颓废 提交于 2019-12-11 04:18:36
问题 I am running a build, and I would like to be able to view the progress as it happens. But I would also like to save the output if the build has an error. I know I can use Process.UseShellExecute = false , and RedirectStandardOutput , but that's only part of the story. How can I do this? 回答1: Update As Greg mentions in the comments below, MSBuild can write out to a log file while also outputting to console out of the box. MSBuild [options] /filelogger /fileloggerparameters:LogFile=MSBuildLog

How to print commands in Python?

﹥>﹥吖頭↗ 提交于 2019-12-11 04:09:25
问题 I'm not in the programming area but I recently got interested in Python. I was writing some functions but for debugging I need to see what commands are running. For instance: def foo(): for i in xrange(0,5): a = 1 + i Is it possible to make the interpreter output >>> for i in xrange(0,5) >>> a = 1 + 0 >>> a = 1 + 1 >>> a = 1 + 2 >>> a = 1 + 3 >>> a = 1 + 4 For >>> foo() Or at least write to a file what is happening? I did some scripting in the past and I remember that this was possible in DOS

Redirect Stdin and Stdout to File

倖福魔咒の 提交于 2019-12-11 03:24:02
问题 I'm currently the Teaching Assistant for an Introduction to C class. The class is being taught using Visual Studio, but when grading I just use a simple Windows batch script to process all the assignment submissions, compile them, run them on a test file, and redirect the output to a series of text files I can print out, mark up, and hand back to students. The whole process works very well, except for the fact that when I redirect stdin, it does not appear in the redirected stdout the same

How can I write to stdIn (JAVA) [duplicate]

北城以北 提交于 2019-12-11 03:02:17
问题 This question already has answers here : JUnit testing with simulated user input (7 answers) Closed 4 years ago . I want to do some tests on my P2P system by using some input like: "join 8". 8 is the Node number. For my system, the command "join 8" is read from stdin, but I don't want to type it hundred times for hundred tests, so I write a test function to randomly generate node numbers and then call the "join" command by itself. So I want JAVA to write commands instead of my own input to

how to return a string from a function which is listening some stream in dart?

只愿长相守 提交于 2019-12-11 02:34:36
问题 i have a function called foo which is listening to the stdout, what i want is to return some string which i got from stdout. here is my function; dynamic foo(process) { return ( process.stdout.transform(UTF8.decoder).listen((data) { String s = data.toString(); // print(s); if (s.contains("received event of")) { var s1 = s.split(":"); print("${s1[1]}"); return s1[1]; } })); } I want to return s1 to the calling function 回答1: This should do what you want Future<String> dynamic foo(process) {