Page 1 of 1

Posted: Thu Jun 06, 2002 1:46 am
by BackupUser
Restored from previous forum. Originally posted by WolfgangS.

HI!
i start an extern program with "Runprogram(blabla)". How can i get the outputstrings of this programm to my variable ? Normaly you can read the outputstring of this extern program in the Standartconsole ...

Sincerely
WolfgangS

Posted: Thu Jun 06, 2002 1:54 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> i start an extern program with "Runprogram(blabla)".
> How can i get the outputstrings of this programm to my variable ?

I don't know how to get it to a variable, but you can use the ShellExecute API
to get the output into a file like so:

Code: Select all

; This example takes the outout of the "dir" command and puts it in a file.
dir$="c:\" ; Folder to examine with the "dir" command.
cmd$=Space(255) : GetEnvironmentVariable_("comspec",cmd$,255) ; Gets "command.com" (Win9x/ME) or "cmd.exe" (Win2K/XP).
ShellExecute_(0,"open",cmd$,"/c dir "+Chr(34)+dir$+"*.*"+Chr(34)+" > "+Chr(34)+dir$+"Output.txt"+Chr(34),dir$,0)

PB - Registered PureBasic Coder

Posted: Thu Jun 06, 2002 7:59 am
by BackupUser
Restored from previous forum. Originally posted by fweil.

Hi all,

PB your code works fine but on my experience, you may need a delay after shellexecute_ (even short like delay(50) on my PC) otherwise file will not exist when processing result.

This is an issue which makes I prefer to use runprogram with the wait for closing flag (set flag to 1 or 1 | 2) to call external programs. The problem is that in some cases redirect is not easy with runprogram because the calling arguments method.

Using runprogram makes necessary to check how calling parameters are to be sent : sometimes in the filename parameter, sometimes in the args parameter (means runprogram("prog args", "", flag) or runprogram("prog", "args", flag).

I experienced both cases according to different external programs.

...

Francois Weil
14, rue Douer
F64100 Bayonne

Posted: Thu Jun 06, 2002 8:24 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> PB your code works fine but on my experience, you may need a delay after
> shellexecute_ (even short like delay(50) on my PC) otherwise file will not
> exist when processing result.

I normally check for the existence of the file after using ShellExecute, like so:

Repeat : Sleep_(1) : Until FileSize(dir$+"Output.txt")-1

That way, I know the file is ready for reading and I don't need to use RunProgram,
which lacks several of the needed ShellExecute parameters.

PB - Registered PureBasic Coder

Posted: Thu Jun 06, 2002 1:49 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Hi WolfgangS,

Maybe you could try the Execute() function from the external CGI library, available at Paul's site:

http://www.reelmediaproductions.com/pb

It uses the CreateProcess API function to allow IO redirecting. In other aspects, it works like RunProgram().

Hope it helps, bye,

El_Choni

Posted: Thu Jun 06, 2002 3:20 pm
by BackupUser
Restored from previous forum. Originally posted by Rings.

Is that what you are looking for:
viewtopic.php?t=952

Its a long way to the top if you wanna .....CodeGuru

Posted: Mon Oct 14, 2002 10:01 pm
by BackupUser
Restored from previous forum. Originally posted by Justin.

That is a very nice example, thanks Rings :)

btw, sorry for bringing this old but good post to the top, i forgot that was the result of a search..