Howto execute external file ...

BlitzMax Forums/BlitzMax Programming/Howto execute external file ...

AndyGFX(Posted 2008) [#1]
How to execute external file (like sh or bat file )from bmx code? Blitz3D has ExecFile(...) and Blitzmax?


GfK(Posted 2008) [#2]
OpenURL("filename.bat")


AndyGFX(Posted 2008) [#3]
thx


AndyGFX(Posted 2008) [#4]
Any idea howto wait on end of executed prgoram? (for showing result)


tonyg(Posted 2008) [#5]
Try system_ such as system_ "notepad.exe"
Might also want to lookup createprocess for more control and do a search on execfile for other solutions.


Htbaa(Posted 2008) [#6]
OpenURL() should only open a external browser when available.

I think you want to use PUB.FreeProcess

Local app:String = "notepad.exe"
'Check if file exists
If FileType(app) = 1
	'Execute application
	Local process:TProcess = CreateProcess(app)
	Repeat
		Local error:String = process.err.ReadLine()
		If error <> "" Then
			Notify error
		EndIf
		If process.Status() = 0 Then Exit
	Forever
Else
	Notify "Unable to execute " + app
EndIf


For my purpose I've left out the repeat block since it was hurting performance for me. But this is how I launch external apps.


GfK(Posted 2008) [#7]
OpenURL() should only open a external browser when available.
OpenURL() will open any file with its default application.

If its a HTML file, it'll open it in the default browser.
If its a .BMX file, it'll open MaxIDE.exe.

etc.


AndyGFX(Posted 2008) [#8]
@Htbaa:
yes. this is good and work nice, thx a lot


Russell(Posted 2012) [#9]
OpenURL works great, and the host program continues running (this may not be the desired behaviour, but it's a start).
System_ works with something like 'System_ "notepad.exe"' but not with a test exe I got from the internet (probably has to do with permissions or security - I have Windows 7 64).
TProcess.CreateProcess returns null, even though FileType() shows the file to be executed exists :(

TProcess.CreateProcess() is not highlighted in my BlitzMax IDE, so maybe something is wrong?

To the point: How does the BlitzMax IDE (or the community edition) call the compiler in the background - I searched but could not find out how - and capture the compiler's output as well?

Thanks in advance,
Russell


PhotonTom(Posted 2012) [#10]
Its Local process:TProcess = TProcess.Create() or Local process:TProcess = CreateProcess()
Its not highlighted in blitzmax as its undocumented but it works.


col(Posted 2012) [#11]
How does the BlitzMax IDE (or the community edition) call the compiler in the background - I searched but could not find out how - and capture the compiler's output as well?


Hiya,

This should help:-


BMKFilePath on Windows defaults to C:\BlitzMax\bin\bmk.exe and ProjectFileName should be self explanatory.

Last edited 2012


Russell(Posted 2012) [#12]
Thanks, col, I'll check it out!

Russell

p.s. I wonder why this is undocumented? Seems quite useful to me! (Makes me wonder what other gems are undocumented in there...)


Russell(Posted 2012) [#13]
It compiles without errors, but doesn't do anything. :(

Any ideas? Or maybe it would be better if someone could tell me where to find the bmk/bcc calling code in the BlitzMax IDE CE source?

Thanks again,
Russell


col(Posted 2012) [#14]
ProjectFilename is the full path including the source filename with extension.


Russell(Posted 2012) [#15]
Geez, I'm such an idiot: I didn't look it over as closely as I should have (didn't replace projectfilename, etc with valid values). And without 'Strict', the variables were given a default value of "".

Anyway, this should do it. Thanks again (again!)
Russell