Execute an external command?

BlitzMax Forums/BlitzMax Programming/Execute an external command?

Is it possible?

which OS? (it can be done with API calls)

On Mac/Win. I'm looking or an exec/run/command(progname, args) type thing. There must be one... or maybe not.

winexec if i can remember correctly... should do it for win32...

--Mike

For mac, you could import some C code which will do it for you. If you know C just look at Fork() and Exec().

Thanks for the suggestions

Try:

system_ cmd$

Compile Error: Identifier 'system_cmd' not found (w/wo space)

Duh - it's late here ;-) Thanks, that works

Any other goodies lurking about?

bear in mind system_ seems to wait until the called process has finished before continuing.

Perturbatio, thanks for the info, that's ok for my use.

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

(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.