Detect Stderr from FBC compiling

DOS specific questions.
lassar
Posts: 240
Joined: Jan 17, 2006 1:35
Contact:

Detect Stderr from FBC compiling

Postby lassar » Feb 08, 2016 18:59

I am working on a program to automate compiling in Freebasic dos.

I need to detect when there is a error in fbc and abort the rest of the program.

Here is what I have so far.

Code: Select all

#lang "FBLITE"

Cmd$ = COMMAND$
SHELL "FBC " + Cmd$

PeriodPos% = Instr(Cmd$,".")
FileName$ = LEFT$(Cmd$,PeriodPos%-1)
ExeName$ = FileName$ + ".exe"


SHELL "exe2coff " + ExeName$
SHELL "copy C:\bin\pmodstub.exe .\"
SHELL "copy /b pmodstub.exe+" + FileName$ + " " + ExeName$




How do I detect when FBC has error?
dkl
Site Admin
Posts: 3166
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Detect Stderr from FBC compiling

Postby dkl » Feb 08, 2016 19:43

Hi,

like many programs, fbc returns a non-zero exit code in case of an error. You can check the result of the shell() function to detect this.

Code: Select all

var result = shell("fbc -version")
select case result
case 0
   print "ok, it worked"
case -1
   print "command not found (or other shell() failure)"
case else
   print "command aborted with exit code " & result
end select


By the way, fbc prints error messages to stdout, not stderr (yea, that's rather non-standard).

If you want to capture the error messages, check out Open Pipe.
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Detect Stderr from FBC compiling

Postby MrSwiss » Feb 09, 2016 11:06

Just a remark on "shelling" from a compiled program:

I've learned "the hard way" that it is usually the better approach, to call a shell script (depending on OS).
The main REASONS are:
- flexibility: can be changed any Time "without touching source code of APPLICATION", recompiling etc.
- script can return Standard Error Codes, or "defined by you" Codes (on exit of script).

Ex. WIN: called "errorlevel" in *.cmd/*.bat (*.cmd = recommended, 32bit Console!)
Ex. DOS: called "errorlevel" in *.bat (16bit Console)
marcov
Posts: 2377
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Detect Stderr from FBC compiling

Postby marcov » Mar 03, 2016 20:51

MrSwiss wrote:Just a remark on "shelling" from a compiled program:

I've learned "the hard way" that it is usually the better approach, to call a shell script (depending on OS).
The main REASONS are:
- flexibility: can be changed any Time "without touching source code of APPLICATION", recompiling etc.
- script can return Standard Error Codes, or "defined by you" Codes (on exit of script).

Ex. WIN: called "errorlevel" in *.cmd/*.bat (*.cmd = recommended, 32bit Console!)
Ex. DOS: called "errorlevel" in *.bat (16bit Console)



OTOH, if you use something CreateProcessW based it will actually be unicode. Running over a shell (cmd.exe) is always in the ansi encoding, and it is hard if not impossible to get accents right that are not in your default encoding.
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Detect Stderr from FBC compiling

Postby MrSwiss » Mar 04, 2016 10:19

marcov wrote:OTOH, if you use something CreateProcessW based it will actually be unicode. Running over a shell (cmd.exe) is always in the ansi encoding, and it is hard if not impossible to get accents right that are not in your default encoding.

Don't understand what you're about ...
This Thread reads DOS = ASCII, not any accenting ("plain old English", *.bat, command.com).
marcov
Posts: 2377
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Detect Stderr from FBC compiling

Postby marcov » Mar 04, 2016 20:35

MrSwiss wrote:
marcov wrote:OTOH, if you use something CreateProcessW based it will actually be unicode. Running over a shell (cmd.exe) is always in the ansi encoding, and it is hard if not impossible to get accents right that are not in your default encoding.

Don't understand what you're about ...
This Thread reads DOS = ASCII, not any accenting ("plain old English", *.bat, command.com).


Then I wonder why the .cmd extension was mentioned. That got me off in the wrong direction. To my best knowledge command.com doesn't do .cmd.
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Detect Stderr from FBC compiling

Postby MrSwiss » Mar 05, 2016 10:31

marcov wrote:Then I wonder why the .cmd extension was mentioned.

A) Clearly marked as Example, by Ex:
B) To show that it's still "the same" (errorlevel) in later OS's
C) Advice for using the "more Modern" Command Processor, if NOT on DOS ...

Maybe a good Example, to illustrate a "quick Shot", that went off, into the wrong Direction ...
BTW: I don't like the "quick Shot" Approach, many here seem to favour (check the Outcome).

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 1 guest