stdout

Send stderr/stdout messages to function and trap exit signal

痞子三分冷 提交于 2019-12-02 01:47:37
问题 Im working on error handling and logging in my bash script. Below I have included a simplified code snippet that exemplify the use case. I want to achieve following in my script: trap exit signals which should trigger onexit() function in the code below stderr and stdout should be sent to the log() function which will make sure to log the output to an log file according to specific log format (simplified in the example below) Issue with current code below: Step 1 is not trapped by onexit

In Eclipse Java EE servlet does not output to console

时光毁灭记忆、已成空白 提交于 2019-12-02 01:20:03
问题 I have a simple servlet that creates HTML with PrintWriter and writes to console via System.out.prinln() in the same doGet() method. I see HTML part in Eclipse (Java EE perspective) but there is nothing in the Console View . Where should stdout from a servlet appear in Eclipse? Code looks like this: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<h2>Hello from Applet<h2>

How to print a string of variables without spaces in Python (minimal coding!) [duplicate]

南笙酒味 提交于 2019-12-02 00:42:11
问题 This question already has answers here : How to print variables without spaces between values [duplicate] (6 answers) Closed 3 years ago . I have something like : print "\n","|",id,"|",var1,"|",var2,"|",var3,"|",var4,"|" It prints with spaces for each variable. | 1 | john | h | johnny | mba | I want something like this : |1|john|h|johnny|mba| I have 20 variables that I have to print and I hate use sys.stdout.write(var) for each one of them. Thanks Pythonistas! 回答1: Try using join : print "\n"

Nodejs always cann't capture child process's stdout data completely, unless child process fllush(stdout)

流过昼夜 提交于 2019-12-02 00:30:21
I use nodejs to captured its child process's stdout data, but always captured the former part of child process's stdout data. When I add fllush(stdout) ,It works OK. But I don't know why, and don't want to add flush(stdout). Here is my code: var tail_child = spawn(exefile, [arg1, arg2, arg3]); tail_child.stdin.write('msg\n'); tail_child.stdout.on('data', function(data) { console.log(data); }); child_process.c printf("data\n"); Need your help! Thank you very much! By default, stdout in general is buffered until a newline is written. However, if stdout is not a tty (which is the case here with

AND in Lua, how is it processed?

牧云@^-^@ 提交于 2019-12-02 00:07:18
问题 I saw this code in a Lua Style Guide print(x == "yes" and "YES!" or x) Context: local function test(x) print(x == "yes" and "YES!" or x) -- rather than if x == "yes" then print("YES!") else print(x) end end What exactly happens at " x == "yes" and "YES!" ? Why does it print "YES!" or (x) not "true" or (x) ? EDIT: Is it like: X == "yes" -- > true true and (value) -- > value print( (x == "yes") and value) So checking x for the value "yes" results in true, adding true to a value gives the value

Python 2.7 build on Sublime Text 3 doesn't print the '\uFFFD' character

谁说胖子不能爱 提交于 2019-12-01 22:44:48
问题 The problem. I'm using Python 2.7 build on Sublime Text 3 and have an issue with printing out. In some cases I get a pretty confusing output for '\uFFFD' - the 'REPLACEMENT CHARACTER' . For example: print u'\ufffd' # should be '�' - the 'REPLACEMENT CHARACTER' print u'\u0061' # should be 'a' ----------------------------------------------------- [Finished in 0.1s] After inversion of the order: print u'\u0061' print u'\ufffd' ----------------------------------------------------- a � [Finished

How to check if stdout has been redirected to NUL on Windows (a.k.a. /dev/null on Linux)?

痴心易碎 提交于 2019-12-01 22:38:47
How can I check if my program's stdout has been redirected to NUL ? That way I can avoid outputting data since it's pointless. I mainly need this for Windows, but if you have a Linux solution, it might be helpful for others in the future, so feel free to post that as well. There are probably other ways to do this (and it wouldn't be a surprise if there turns out to be a proper function for it I've overlooked), but here's one way: enum { Output_Console, Output_File, Output_NUL, }; bool GetOutputHandleType(int* piType) { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h) { BY_HANDLE_FILE

How to get the name of a file acting as stdin/stdout?

假如想象 提交于 2019-12-01 21:11:16
I'm having the following problem. I want to write a program in Fortran90 which I want to be able to call like this: ./program.x < main.in > main.out Additionally to "main.out" (whose name I can set when calling the program), secondary outputs have to be written and I wanted them to have a similar name to either "main.in" or "main.out" (they are not actually called "main"); however, when I use: INQUIRE(UNIT=5,NAME=sInputName) The content of sInputName becomes "Stdin" instead of the name of the file. Is there some way to obtain the name of files that are linked to stdin/stdout when the program

AND in Lua, how is it processed?

依然范特西╮ 提交于 2019-12-01 21:07:15
I saw this code in a Lua Style Guide print(x == "yes" and "YES!" or x) Context: local function test(x) print(x == "yes" and "YES!" or x) -- rather than if x == "yes" then print("YES!") else print(x) end end What exactly happens at " x == "yes" and "YES!" ? Why does it print "YES!" or (x) not "true" or (x) ? EDIT: Is it like: X == "yes" -- > true true and (value) -- > value print( (x == "yes") and value) So checking x for the value "yes" results in true, adding true to a value gives the value and printing this process prints the value, right? From the docs : The operator and returns its first

Redirect system2 stdout to a file on windows

两盒软妹~` 提交于 2019-12-01 20:51:22
According to the manual , the stdout argument of the system2 function can redirect output to a file. This seems to work on unix, however I can't get it to work on windows. The toy example below, no out.txt or err.txt files are created. I tried sending it to an existing file, or expand the full file path, but with no success: setwd(tempdir()) system2("whoami", stdout="out.txt", stderr="err.txt") file.exists("out.txt") Am I doing something wrong or is this a limitation in system2 ? I'm quite convinced now this is a bug in RGui.exe in windows. I filed a bug report here: https://bugs.r-project.org