stdout

NodeJS spawn stdout string format

时间秒杀一切 提交于 2019-12-21 07:26:08
问题 I'm spawning a process in node and tracking the output of the command like this: proc.stdout.on("data", function (data) { console.log(data.toString()); }); It works well, however, the output seems to be splitting the lines: npm http 304 https://registry.npmjs.org/underscore The above is just one line out of the response from an npm install . Typically this is all in one line, it's also adding line breaks before and after the response. Is there a way to get the data output to look like the

C++ duplicate stdout to file by redirecting cout

风格不统一 提交于 2019-12-21 05:54:05
问题 Good day. I have to use some external functions that produce a lot of debugging information to stdout (via std::cout ). I want to duplicate this information to some log file by redirecting cout to boost tee_device . I use the following example code: typedef boost::iostreams::tee_device<ostream, ofstream> TeeDevice; typedef boost::iostreams::stream<TeeDevice> TeeStream; int main(int argc, char** argv) { remove("file.log"); ofstream logFile; logFile.open("file.log"); TeeDevice outputDevice(cout

How to ensure that we read all lines from boost::child process

和自甴很熟 提交于 2019-12-21 04:17:07
问题 I saw the following code on boost::child documentation page where they explain how to read the output of a child process. http://www.boost.org/doc/libs/1_64_0/doc/html/boost_process/tutorial.html They say after running your child process, we can read it via this loop:- bp::ipstream is; //reading pipe-stream bp::child c(bp::search_patk("nm"), file, bp::std_out > is); //then later while (c.running() && std::getline(is, line) && !line.empty()) data.push_back(line); I have 2 questions here :- If

Python: get output from a command line which exits with nonzero exit code

别来无恙 提交于 2019-12-21 02:41:58
问题 I am Using Python 2.7.1 on a Windows Server 2008 R2 x64 box. I'm trying to get the output of a command line process which gives a nonzero exit status after outputting the information I need. I was initially using subprocess.check_output , and catching the CalledProcessError which occurs with nonzero exit status, but while the returncode was stored in the error, no output revealed this. Running this against cases which give output but have an exit status of 0 works properly and I can get the

Redirecting stdout/stderr to multiple files

一笑奈何 提交于 2019-12-20 10:48:23
问题 I was wondering how to redirect stderr to multiple outputs. I tried it with this script, but I couldn't get it to work quite right. The first file should have both stdout and stderr, and the 2nd should just have errors. perl script.pl &> errorTestnormal.out &2> errorTest.out Is there a better way to do this? Any help would be much appreciated. Thank you. 回答1: perl script.pl 2>&1 >errorTestnormal.out | tee -a errorTestnormal.out > errorTest.out Will do what you want. This is a bit messy, lets

Catching/hijacking stdout in haskell

◇◆丶佛笑我妖孽 提交于 2019-12-20 10:37:55
问题 How can I define 'catchOutput' so that running main outputs only 'bar'? That is, how can I access both the output stream (stdout) and the actual output of an io action separately? catchOutput :: IO a -> IO (a,String) catchOutput = undefined doSomethingWithOutput :: IO a -> IO () doSomethingWithOutput io = do (_ioOutp, stdOutp) <- catchOutput io if stdOutp == "foo" then putStrLn "bar" else putStrLn "fail!" main = doSomethingWithOutput (putStr "foo") The best hypothetical "solution" I've found

Using files as stdin and stdout for subprocess

你离开我真会死。 提交于 2019-12-20 10:24:28
问题 How do I replicate the following batch command using python subprocess module? myprogram < myinput.in > myoutput.out In other words, how do I run myprogram using the contents of myinput.in as the standard input and myoutput.out as standard output? 回答1: The following should work: myinput = open('myinput.in') myoutput = open('myoutput.out', 'w') p = subprocess.Popen('myprogram.exe', stdin=myinput, stdout=myoutput) p.wait() myoutput.flush() 来源: https://stackoverflow.com/questions/15167603/using

Why does 2>&1 need to come before a | (pipe) but after a “> myfile” (redirect to file)?

*爱你&永不变心* 提交于 2019-12-20 08:44:44
问题 When combining stderr with stdout, why does 2>&1 need to come before a | (pipe) but after a > myfile (redirect to file)? To redirect stderr to stdout for file output: echo > myfile 2>&1 To redirect stderr to stdout for a pipe: echo 2>&1 | less My assumption was that I could just do: echo | less 2>&1 and it would work, but it doesn't. Why not? 回答1: A pipeline is a |-delimited list of commands . Any redirections you specify apply to the constituent commands (simple or compound), but not to the

How can I capture the stdout from a process that is ALREADY running

自作多情 提交于 2019-12-20 08:42:47
问题 I have a running cron job that will be going for a while and I'd like to view its stdout. I don't know how important the fact that the process was started by cron is, but I figure I'd mention it. This is on OSX so, I don't have access to things like... /proc/[pid]/..., or truss, or strace. Suggestions of executing with IO redirection (e.g. script > output & tail -f output ) are NOT acceptable, because this process is 1) already running, and 2) can't be stopped/restarted with redirection. If

How can I capture the stdout from a process that is ALREADY running

↘锁芯ラ 提交于 2019-12-20 08:42:15
问题 I have a running cron job that will be going for a while and I'd like to view its stdout. I don't know how important the fact that the process was started by cron is, but I figure I'd mention it. This is on OSX so, I don't have access to things like... /proc/[pid]/..., or truss, or strace. Suggestions of executing with IO redirection (e.g. script > output & tail -f output ) are NOT acceptable, because this process is 1) already running, and 2) can't be stopped/restarted with redirection. If