System calls?
BlitzMax Forums/BlitzMax Beginners Area/System calls?
| ||
I can't find how to do system calls in BMax (I.e. calling a bash script in linux/ batch file in windows for example) Surely there must be a way, but I haven't been able to locate it in the docs! |
| ||
Just use System_(cmd:String). |
| ||
huh - i can't find that in the command reference anywhere, and it doesn't even highlight in the IDE! Thanks! |
| ||
Yeah, it's undocumented. It's more of a behind-the-scenes function call. You could always use OpenURL also. |
| ||
But, OpenURL will do some magic in certain cases, like on Linux:Method OpenURL( url$ ) If getenv_("KDE_FULL_DESKTOP") system_ "kfmclient exec ~q"+url+"~q" ElseIf getenv_("GNOME_DESKTOP_SESSION_ID") system_ "gnome-open ~q"+url+"~q" EndIf End Method The intention for OpenURL is to open files/web pages, not launching programs (even though that is a side effect). I would recommend using system_() or TProcess (which is actually a pita to use). |
| ||
I tried this out with :- ' ** System call example to launch external program within a running blitzmax program ** SuperStrict Local Cmd:String = "C:\Unlock.exe" ' Name of external program to run. Local S:TStream=OpenFile(Cmd) If Not S Notify("File not found error!") Else Print "Launching external command..." System_(Cmd:String) ' command executes and program suspends until complete. Print "Complete." EndIf End but that doesn't work yet it did when i first tried it but never since. I know it's a cludgy test if file exists line in there but it wont even work without that check now which is odd. Any ideas? Oh, and a nicer way to check if a file exists would be great too if someone is feeling generous :) |
| ||
@Xerra: You can use FileType(path) to test paths. The return values are FILETYPE_FILE (path exists, and it is a file), FILETYPE_DIR (path exists, and it is a directory) and FILETYPE_NONE (path does not exist). system_() should work as you are using it, if the path exists. EDIT: Also, you're opening a stream to the path which is never closed. This is probably why the execution doesn't work (the file is opened as read/write, meaning nothing else can access it until the stream is closed). |
| ||
Oh man - of course. Thanks plash - that would explain perfectly why it didn't work after one try. |
| ||
' ** System call example to launch external program within a running blitzmax program ** SuperStrict Local Cmd:String = "C:\Unlock.exe" ' Name of external program to run. Local S:Byte=FileType(Cmd) If Not S Notify("File not found error!") Else Print "Launching external command..." System_(Cmd:String) ' command executes and program suspends until complete. Print "Complete." EndIf End in other words. Works just fine. |