How can I display a ‘naked’ error message in PowerShell without an accompanying stacktrace?

Preface re what doesn’t work: Setting the $ErrorView preference variable $ErrorView variable to ‘CategoryView’ causes PowerShell to output concise, single-line error representations instead, but this representation may not always include enough information, because the error message is typically not included; on the plus side, the text passed to Throw “…” is reflected, but, by contrast, … Read more

Get error code from within a batch file

Sounds like you’ll want the “If Errorlevel” command. Assuming your executable returns a non-0 exit code on failure, you do something like: myProgram.exe if errorlevel 1 goto somethingbad echo Success! exit :somethingbad echo Something Bad Happened. Errorlevel checking is done as a greater-or-equal check, so any non-0 exit value will trigger the jump. Therefore, if … Read more

How to test os.exit scenarios in Go

There’s a presentation by Andrew Gerrand (one of the core members of the Go team) where he shows how to do it. Given a function (in main.go) package main import ( “fmt” “os” ) func Crasher() { fmt.Println(“Going down in flames!”) os.Exit(1) } here’s how you would test it (through main_test.go): package main import ( … Read more

How do you capture stderr, stdout, and the exit code all at once, in Perl?

(Update: I updated the API for IO::CaptureOutput to make this even easier.) There are several ways to do this. Here’s one option, using the IO::CaptureOutput module: use IO::CaptureOutput qw/capture_exec/; my ($stdout, $stderr, $success, $exit_code) = capture_exec( @cmd ); This is the capture_exec() function, but IO::CaptureOutput also has a more general capture() function that can be … Read more

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