Execute an external command?

BlitzMax Forums/BlitzMax Programming/Execute an external command?

dmoc(Posted 2005) [#1]
Is it possible?


Perturbatio(Posted 2005) [#2]
which OS? (it can be done with API calls)


dmoc(Posted 2005) [#3]
On Mac/Win. I'm looking or an exec/run/command(progname, args) type thing. There must be one... or maybe not.


Red Ocktober(Posted 2005) [#4]
winexec if i can remember correctly... should do it for win32...

--Mike


rdodson41(Posted 2005) [#5]
For mac, you could import some C code which will do it for you. If you know C just look at Fork() and Exec().


dmoc(Posted 2005) [#6]
Thanks for the suggestions


marksibly(Posted 2005) [#7]
Try:

system_ cmd$


dmoc(Posted 2005) [#8]
Compile Error: Identifier 'system_cmd' not found (w/wo space)


dmoc(Posted 2005) [#9]
Duh - it's late here ;-) Thanks, that works


dmoc(Posted 2005) [#10]
Any other goodies lurking about?


Perturbatio(Posted 2005) [#11]
bear in mind system_ seems to wait until the called process has finished before continuing.


dmoc(Posted 2005) [#12]
Perturbatio, thanks for the info, that's ok for my use.


Muttley(Posted 2005) [#13]
For some reason when using system_ redirects seem to not work (on Windows, at least).

If, for example, you do the following on a command line the output is sent to a file:
echo > test.txt

But if in Max you do this:
system_("echo > test.txt")
the output just goes to the screen.

Any ideas? This has me stumped and I'm relying on being able to parse the output from an external command. :(

According to all the docs I can find on the net, redirects should work with the system() call.

Cheers

Muttley


EOF(Posted 2005) [#14]
(Recently posted on another thread)



This should work on all three systems. Not certain though.
It uses Skids excellent FreeProcess library.

I have pulled various bits out of my FrameWork Assistant to show you how I launch an external program:

First, import skidracers module:
Import PUB.FreeProcess

Now create a global TProcess variable:
Global proc:TProcess

When you are ready to launch an external program:
Function RunApp(myapp$)
    ' check if application is still running
    If proc<>Null
        If proc.Status()
            Notify "program still running!"
            Return
        EndIf
    EndIf
    ' run program
    proc=TProcess.Create(myapp$,0)
    If Not Proc
        Notify "Failed to launch "+myapp$
    EndIf
End Function


What's nice about this method is, you can prevent multiple launches of an application (as I do above) and when you close your own program Max shuts down the running app too.