ERRORLEVEL issue

99 views
Skip to first unread message

Walter Weinmann

unread,
Sep 21, 2020, 2:44:54 AM9/21/20
to golang-nuts
Sorry - unfortunately I am a beginner.

I have a Golang program that runs on an error and ends with panic(). When running on Windows 10 the value of ERRORLEVEL is 0, the same happens when the program is terminated with exit(1).

What am I doing wrong? 

Kurtis Rader

unread,
Sep 21, 2020, 2:55:55 AM9/21/20
to Walter Weinmann, golang-nuts
Insufficient data. When I run a Go program that does `os.Exit(1)` in a MSYS2 bash shell doing `echo $status` shows the value `1` as expected. Running the same program inside a cmd.exe shell and then doing `echo %ERRORLEVEL%` also reports `1` as expected.
 
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Kurtis Rader

unread,
Sep 21, 2020, 3:38:11 AM9/21/20
to Walter Weinmann, golang-nuts
I also wrote a trivial Go program that did nothing more than `panic("WTF")` and it results in an exit status (ERRORLEVEL) of two in both a MSYS2 bash shell and a native cmd.exe shell. So, it is likely you are not testing what you think you are testing.

On Sun, Sep 20, 2020 at 7:44 PM Walter Weinmann <walter....@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a875f3d3-0f51-4cd8-91d5-5cf08f51223an%40googlegroups.com.

Walter Weinmann

unread,
Sep 21, 2020, 6:51:19 AM9/21/20
to golang-nuts
My code is here:

Screenshot 2020-09-21 084403.png

My script is here:


Screenshot 2020-09-21 084604.png

Logfile:

Screenshot 2020-09-21 084819.png

Same problem with os.Exit(1).

What am I doing wrong?

Tamás Gulácsi

unread,
Sep 21, 2020, 7:15:07 AM9/21/20
to golang-nuts
You're building src_go.exe (-o of go build), and running orabench.exe.

Walter Weinmann

unread,
Sep 21, 2020, 7:19:41 AM9/21/20
to Tamás Gulácsi, golang-nuts
I'm not - sec_go is a directory:

Screenshot 2020-09-21 091724.png

This looks as expected ?

You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/pQR3qH3JQ2g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/51159fc4-9399-4b92-8cbd-fd6ad97bbe28n%40googlegroups.com.


--
 
___________________________________________________________________________
Walter Weinmann
___________________________________________________________________________
Grabenstrasse 13
CH-6004 Luzern
___________________________________________________________________________

Brian Candler

unread,
Sep 21, 2020, 7:37:57 AM9/21/20
to golang-nuts
On Monday, 21 September 2020 07:51:19 UTC+1, Walter Weinmann wrote:
Same problem with os.Exit(1).


Are you saying that if you run this program:

package main
import "os"
func main() {
    os.Exit(1)
}

you see the %ERRORLEVEL% is 0?

Under Linux, calling os.Exit(1) also prints the message "exit status 1".  Does this happen with Windows too?

What version of go are you using?  And which shell are you using to run the script which runs the executable?

Walter Weinmann

unread,
Sep 21, 2020, 8:37:04 AM9/21/20
to golang-nuts
This simple version is working - it seems to be a more specific issue.  

Brian Candler

unread,
Sep 21, 2020, 9:12:41 AM9/21/20
to golang-nuts
Are you making an explicit call to panic(), or is it a crash from inside some cgo?  If you are calling panic() is it from somewhere unusual like a signal handler?

I tried a small cgo program to fault and it still exited with code 1 (under macOS anyway) - incidentally the word "panic" doesn't appear in the output.

package main

// typedef int (*intFunc) ();
//
// int
// bridge_int_func()
// {
// return ((intFunc)0)();
// }
import "C"
import "fmt"

func main() {
fmt.Println(int(C.bridge_int_func()))
}

And this one exits with code 2:

package main

// int
// bridge_int_func()
// {
// return *(volatile int *)0;
// }
import "C"
import "fmt"

func main() {
fmt.Println(int(C.bridge_int_func()))
}

Wojciech S. Czarnecki

unread,
Sep 21, 2020, 9:50:56 AM9/21/20
to golan...@googlegroups.com
Dnia 2020-09-20, o godz. 23:51:19
Walter Weinmann <walter....@gmail.com> napisał(a):

> [image: Screenshot 2020-09-21 084403.png]
> [image: Screenshot 2020-09-21 084604.png]
> [image: Screenshot 2020-09-21 084819.png]

Please DO NOT post screenshots of text to this list.

@ Tamás Gulácsi, @ Brian Candler, @ Kurtis Rader

Please DO NOT reply to posts containing screenshots of text.

--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE
Reply all
Reply to author
Forward
0 new messages