Return information from a Shell

New to FreeBASIC? Post your questions here.
KenHorse
Posts: 56
Joined: Jan 27, 2012 0:08

Re: Return information from a Shell

Post by KenHorse »

Well...after playing a bit, I found that if I Print Err right after opening the pipe, there is no need for any intervention (no need to press ENTER twice).

Go figure..

Code: Select all

dim csysname as string
dim xfnum as long

xfnum = freefile()
open pipe "/usr/sbin/asterisk -rx 'rpt showvars 1100'" for input as #xfnum
print  Err

do while( not eof( xfnum ) )
  input #xfnum, csysname
  ? "Data From ASL " ; csysnameloop

close #xfnum
KenHorse
Posts: 56
Joined: Jan 27, 2012 0:08

Re: Return information from a Shell

Post by KenHorse »

Now all I need to do is figure out how to send a Print statement to /dev/null!
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Return information from a Shell

Post by badidea »

Normally you redirect print output by adding a command line parameter, e.g.:

Code: Select all

./test > /dev/null
where 'test' is the name of your program.

I do not know how to redirect stdout form code. Maybe like this:

Code: Select all

#include once "crt/stdio.bi"
dim as string redirect_file = "/dev/null" '"test.xxx"

dim as FILE ptr filePtr
print "test_123"
filePtr = freopen(redirect_file, "w+", stdout)
if filePtr <> 0 then
	print "test_456" 'this output is redirected
	fclose(filePtr)
else
	print "Error"
end if
print "test_789" 'this also, a reset is needed
Here is more console hacking: https://freebasic.net/forum/viewtopic.php?f=3&t=9690
Post Reply