stdout

how to print directly to a text file in both python 2.x and 3.x?

十年热恋 提交于 2019-12-04 23:28:44
Instead of using write() , what are the other way to write to a text file in Python 2 and 3? file = open('filename.txt', 'w') file.write('some text') You can use the print_function future import to get the print() behaviour from python3 in python2: from __future__ import print_function with open('filename', 'w') as f: print('some text', file=f) If you do not want that function to append a linebreak at the end, add the end='' keyword argument to the print() call. However, consider using f.write('some text') as this is much clearer and does not require a __future__ import. f = open('filename.txt

stdout vs console.write in c#

自古美人都是妖i 提交于 2019-12-04 22:56:56
I am VERY new to C#/programming and as a learning exercise completed an online challenge to change text to lowercase. The challenge specified it must 'print to stdout' yet I completed the challenge by using Console.Writeline using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lowercase { class Program { static void Main(string[] args) { using ( StreamReader reader = new StreamReader("TextFile1.txt")) { while (!reader.EndOfStream) { string line = reader.ReadLine(); Console.WriteLine(line.ToLower()); }

How can I split and re-join STDOUT from multiple processes?

夙愿已清 提交于 2019-12-04 20:35:34
问题 I am working on a pipeline that has a few branch points that subsequently merge-- they look something like this: command2 / \ command1 command4 \ / command3 Each command writes to STDOUT and accepts input via STDIN. STDOUT from command1 needs to be passed to both command2 and command3, which are run sequentially , and their output needs to be effectively concatenated and passed to command4. I initially thought that something like this would work: $ command1 | (command2; command3) | command4

phantomjs pdf to stdout

我的未来我决定 提交于 2019-12-04 18:48:50
问题 I am desperately trying to output a PDF generated by phantomJS to stdout like here What I am getting is an empty PDF file, although it is not 0 in size, it displays a blank page. var page = require('webpage').create(), system = require('system'), address; address = system.args[1]; page.paperSize = {format: 'A4'}; page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(); } else { window.setTimeout(function () { page.render('

bash variable capture stderr and stdout separately or get exit value [duplicate]

半世苍凉 提交于 2019-12-04 16:10:48
问题 This question already has answers here : Capture stdout and stderr into different variables (13 answers) Closed 4 years ago . I need to capture the output and error of a command in my bash script and know whether the command succeeded or not. At the moment, I am capturing both like this: output=$(mycommand 2>&1) I then need to check the exit value of mycommand. If it failed, I need to do some stuff with the output, if the command succeeded, I don't need to touch the output. Since I am

How can I roll over Tomcat 5.5 stderr and stdout files when they get too large/big?

為{幸葍}努か 提交于 2019-12-04 16:01:28
I have been trying to figure out a way to take the Tomcat 5.5 stderr and stdout log files and roll them over when they get too large, but I have been unable to do so. Now, please understand this is NOT for web app logging. This is just the stdout and stderr logs that are automatically created by Tomcat. Again, they get too large, and I just need a method to roll them over when they get too large and/or on a time interval (i.e. every day, every hour). I tried using log4j, but that appears to be geared for application logging, not so much for tomcat. There was a method I found that states it can

Show output from child scripts in the parent console window

妖精的绣舞 提交于 2019-12-04 15:59:18
I'm calling VBScripts from inside of a VBScript and I want their console output to appear in the window from which I'm calling them. So when I have this code WScript.Stdout.WriteLine( "Checking out unit tests" ) ObjWshShell.Run "%comspec% \c checkoutUnitTests.vbs", 0, True the the only output I see is Checking out unit tests when I want to see all the output from checkoutUnitTests.vbs concatenated onto that output in the same window. How do I do this? Ekkehard.Horner You should try to use .Exec and .Stdout.Readline() as in this bare bone demo script: mother.vbs Option Explicit Dim oWS : Set

Print a string to stdout using Logstash 1.4?

爷,独闯天下 提交于 2019-12-04 15:28:50
So I was testing this config for using metrics from the Logstash website here . input { generator { type => "generated" } } filter { if [type] == "generated" { metrics { meter => "events" add_tag => "metric" } } } output { # only emit events with the 'metric' tag if "metric" in [tags] { stdout { message => "rate: %{events.rate_1m}" } } } But it looks like the "message" field for stdout was deprecated. What is the correct way to do this in Logstash 1.4? So figured it out after looking at the JIRA page for Logstash. NOTE: The metrics only print or "flush" every 5 seconds so if you are generating

How to implement a stdin, stdout wrapper?

拥有回忆 提交于 2019-12-04 14:13:09
问题 I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly. How to implement this ? X and Y can be hardcoded. Bash? Python? Edit: I can't run the program twice. It has to be one instance. Here is the pseudocode: def wrap(cmd, in, expected_out): p = exec(cmd) p.writeToStdin(in) out = p.readBytes

Redirecting stdout from another program in C++

梦想与她 提交于 2019-12-04 14:07:08
问题 I'm writing a unit test and therefore, cannot change the code within the file that I'm testing. The code that I'm testing has messages in cout that I am trying to redirect into a file to check to make sure that the program is outputting the right messages. Does anyone have a way to redirect stdout in another program that won't cause a lag? I have tried freopen() and that causes my program to hang for some reason. 回答1: You could create a filebuf then replace cout 's streambuf with it: { std: