Redirecting standard output of compiled executables (Window)

New to FreeBASIC? Post your questions here.
Post Reply
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Redirecting standard output of compiled executables (Window)

Post by Flyzone »

I'm having trouble redirecting the output of a compiled program (using the redirection operator ">"). A file seems to be created but is apparently not closed properly showing zero bytes and therefore is unreadable.

For example, the following program is executed from within another FreeBasic program by "SHELL "c:\freebasic\fbc64 f.bas > ans". The f.bas program should place the output of the print commands to a file named ANS but it does not as stated above. This appears to be more or a Windows question using Freebasic. This process works with Microsoft's Basic interpreter.

Code: Select all

#lang "fblite"
b=4
c=5
?"b+c"
?b+c
SYSTEM
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Redirecting standard output of compiled executables (Window)

Post by grindstone »

Change the call to "SHELL "c:\freebasic\fbc64 f.exe > ans" and it should work.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Redirecting standard output of compiled executables (Window)

Post by dodicat »

SHELL "c:\freebasic\fbc64 f.bas > ans"
will only write the compiler output to ans.
e.g.
SHELL "c:\freebasic\fbc64 -v f.bas > ans"
will fill ans with something you can read.
Grindstone's suggestion will work.
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Redirecting standard output of compiled executables (Window)

Post by Flyzone »

grindstone wrote: Dec 03, 2022 8:58 Change the call to "SHELL "c:\freebasic\fbc64 f.exe > ans" and it should work.
Of course. My head was up my arse on this one. Actually for my purpose I just needed "SHELL f.exe > ans"

Thanks.

EDIT: Actually I had to break it up into two consecutive SHELL commands; 1 to compile, 2 to execute, which substitutes for the Microsoft interpreter that executes while compiling.
Post Reply