[Gambas-user] Reading the return from a shell command

Rob sourceforge-raindog2 at ...94...
Fri Jan 21 15:58:19 CET 2005


On Friday 21 January 2005 05:01, Dave sharples wrote:
> I am trying to issue a shell command from gambas with a couple
> of arguments and use the return value in my app but I an
> struggling to get a grasp on how to do it.

You need to use the Process_Read event and grab the data as it 
comes in.  Sometimes that's inconvenient and you want to do it 
asynchronously, so I wrote the Backtick function, which you can 
find in Help somewhere, but here it is again:

STATIC PUBLIC FUNCTION Backtick(cmd AS String) AS String
  DIM result AS String
  DIM s AS String
  result = ""
  s = Temp()
  SHELL cmd & " >" & s WAIT
  TRY result = file.Load(s)
  TRY KILL s
  RETURN result
END

It's called "Backtick" because it does more or less what the 
backtick (``) quotes do in the Unix shell and in perl.

Rob






More information about the User mailing list