Making curl send errors to stderr and everything else to stdout

Try this: # No error messages because it succeeds. curl http://www.shikadi.net/ –fail –silent –show-error # This prints an error message to stderr curl http://i.like.you.def.maybe/ –fail –silent –show-error Thanks to Russell Davis’s answer on this page, man curl, and trial and error. For the curious, here is the wget version of the question: https://superuser.com/questions/420120/wget-is-silent-but-it-displays-error-messages

How do I temporarily redirect stderr in Ruby?

In Ruby, $stderr refers to the output stream that is currently used as stderr, whereas STDERR is the default stderr stream. It is easy to temporarily assign a different output stream to $stderr. require “stringio” def capture_stderr # The output stream must be an IO-like object. In this case we capture it in # an … Read more

“subprocess.Popen” – checking for success and errors

Do you need to do anything with the output of the process? The check_call method might be useful here. See the python docs here: https://docs.python.org/2/library/subprocess.html#subprocess.check_call You can then use this as follows: try: subprocess.check_call(command) except subprocess.CalledProcessError: # There was an error – command exited with non-zero code However, this relies on command returning an exit … Read more

Redirect subprocess stderr to stdout

In Python < v3.5: A close read of the source code gives the answer. In particular, the documentation is misleading when it says: subprocess.STDOUT Special value that (…) indicates that standard error should go into the same handle as standard output. Since stdout is set to “default” (-1, technically) when stderr=subprocess.STDOUT is evaluated, stderr is … Read more

Merging a Python script’s subprocess’ stdout and stderr while keeping them distinguishable

tsk = subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) subprocess.STDOUT is a special flag that tells subprocess to route all stderr output to stdout, thus combining your two streams. btw, select doesn’t have a poll() in windows. subprocess only uses the file handle number, and doesn’t call your file output object’s write method. to capture the output, do something like: logfile … Read more

How do I write to standard error in PowerShell?

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 writes errors as error records. If you want to avoid the verbose output of the error records, you could write out the error info yourself like so: PS> Write-Error “oops” -ev … Read more

How is STDERR.puts different from puts in Ruby?

By default, puts writes to STDOUT. By specifying STDERR.puts, you’re sending your output to the STDERR handle. Although the implementation behavior is the same, using STDERR instead of STDOUT will definitely impact consumers of your program, since they will be attempting to capture output from your program from STDOUT, by convention. Best practice is to … Read more

Capture program stdout and stderr to separate variables

One option is to combine the output of stdout and stderr into a single stream, then filter. Data from stdout will be strings, while stderr produces System.Management.Automation.ErrorRecord objects. $allOutput = & myprogram.exe 2>&1 $stderr = $allOutput | ?{ $_ -is [System.Management.Automation.ErrorRecord] } $stdout = $allOutput | ?{ $_ -isnot [System.Management.Automation.ErrorRecord] }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)