stderr

How to execute a command and get return code stdout and stderr of command in C++

随声附和 提交于 2019-12-18 12:36:23
问题 Given the following answer (first c++11 answer): How to execute a command and get output of command within C++ using POSIX? Here is the implementation for your convinience: #include <cstdio> #include <iostream> #include <memory> #include <stdexcept> #include <string> #include <array> std::string exec(const char* cmd) { std::array<char, 128> buffer; std::string result; std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose); if (!pipe) throw std::runtime_error("popen() failed!"); while (!feof(pipe

How to redirect a program that writes to tty?

喜欢而已 提交于 2019-12-18 06:59:09
问题 This is the un-redirected output (if you don't know what module is, it doesn't matter much): $ module help null ----------- Module Specific Help for 'null' ----------------------- This module does absolutely nothing. It's meant simply as a place holder in your dot file initialization. Version 3.2.6 Suppose I'd like to redirect that to a file.... $ module help null > aaa.txt ----------- Module Specific Help for 'null' ----------------------- This module does absolutely nothing. It's meant

Shell(六):输入/输出重定向

*爱你&永不变心* 提交于 2019-12-17 17:02:05
重定向的作用是将命令的执行结果输出到指定的文件中。 重定向命令列表如下: 文件描述符 0 通常是标准输入(STDIN), 1 是标准输出(STDOUT), 2 是标准错误输出(STDERR)。 1、输出重定向 将输出重定向到file示例: 注意,任何file1内的已经存在的内容将被新内容替代,更改file1,再次重定向: 如果要将新内容添加在文件末尾,需要使用>>操作符: 2、输入重定向 注意:上面两个例子的结果不同:第一个例子,会输出文件名;第二个不会,因为它仅仅知道从标准输入读取内容。 重定向输入和输出可以同时使用: 一般情况下,每个 Unix/Linux 命令运行时都会打开三个文件: 标准输入文件(stdin):stdin的文件描述符为0,Unix程序默认从stdin读取数据。 标准输出文件(stdout):stdout 的文件描述符为1,Unix程序默认向stdout输出数据。 标准错误文件(stderr):stderr的文件描述符为2,Unix程序会向stderr流中写入错误信息。 默认情况下,command > file 将 stdout 重定向到 file,command < file 将stdin 重定向到 file。 如果希望 stderr 重定向到 file,可以这样写: $ command 2> file 如果希望 stderr 追加到 file 文件末尾

How do I write to standard error in PowerShell?

放肆的年华 提交于 2019-12-17 15:39:30
问题 I'm having trouble figuring out how to both echo to the standard error stream and redirect the error stream of an executable. I have come from a Bourne shell and Korn shell background, of which I would use; # Write to stderr echo "Error Message!" >&2 # Redirect stderr to file /do/error 2>/tmp/err.msg 回答1: Use Write-Error to write to stderr. To redirect stderr to file use: Write-Error "oops" 2> /temp/err.msg or exe_that_writes_to_stderr.exe bogus_arg 2> /temp/err.msg Note that PowerShell

Difference between $stdout and STDOUT in Ruby

不问归期 提交于 2019-12-17 15:24:22
问题 In Ruby, what is the difference between $stdout (preceded by a dollar sign) and STDOUT (in all caps)? When doing output redirection, which should be used and why? The same goes for $stderr and STDERR . Edit: Just found a related question. 回答1: $stdout is a global variable that represents the current standard output. STDOUT is a constant representing standard output and is typically the default value of $stdout . With STDOUT being a constant, you shouldn't re-define it, however, you can re

Make cURL output STDERR to file (or string)

。_饼干妹妹 提交于 2019-12-17 12:24:05
问题 We're trying to debug some cURL errors on the server, and I would like to see the STDERR log. Currently, all we can see for our error is "error code: 7" and that we can't connect to target server. We have contacted the host and made special rule to open the port we need and we're even ignoring the certificate for the time being. Still, we can't connect. I need to debug this, but I can't see any pertinent information on my end. The lines mentioning "VERBOSE" and "STDERR" are the most important

Piping both stdout and stderr in bash?

久未见 提交于 2019-12-17 07:04:33
问题 It seems that newer versions of bash have the &> operator, which (if I understand correctly), redirects both stdout and stderr to a file ( &>> appends to the file instead, as Adrian clarified). What's the simplest way to achieve the same thing, but instead piping to another command? For example, in this line: cmd-doesnt-respect-difference-between-stdout-and-stderr | grep -i SomeError I'd like the grep to match on content both in stdout and stderr (effectively, have them combined into one

Why does 'java -version' go to stderr?

你说的曾经没有我的故事 提交于 2019-12-17 04:06:15
问题 Is there any special reason for the results of java -version going to stderr ? For example, this command executed from Windows' prompt line: java -version > java_version.txt leaves the file java_version.txt empty. EDIT: The same happens with the help printed out after executing java.exe without any parameters. EDIT: Just out of a sheer curiosity I checked whether it has been always like that and it turned out it actually has. java -version goes to stderr in JDK 1.1.8 and also in JDK 1.2.2,

PHP StdErr after Exec()

北城以北 提交于 2019-12-17 01:57:33
问题 In PHP I am executing a command with exec(), and it returns if successful an URL; $url = exec('report'); However, I want to check stderr, if something went wrong. How would I read the stream? I want to use php://stderr, but I am not sure how to use it. 回答1: If you want to execute a command, and get both stderr and stdout , not "merged", a solution would probably to use proc_open, which provides a great level of control over the command that's being executed -- including a way to pipe stdin /

How to pipe stderr, and not stdout?

為{幸葍}努か 提交于 2019-12-16 19:44:55
问题 I have a program that writes information to stdout and stderr , and I need to grep through what's coming to stderr , while disregarding stdout . I can of course do it in 2 steps: command > /dev/null 2> temp.file grep 'something' temp.file but I would prefer to be able to do this without temp files. Are there any smart piping tricks? 回答1: First redirect stderr to stdout — the pipe; then redirect stdout to /dev/null (without changing where stderr is going): command 2>&1 >/dev/null | grep