CreateProcess to exectute bmk

BlitzMax Forums/BlitzMax Programming/CreateProcess to exectute bmk

JonasL(Posted 2009) [#1]
I need to execute bmk using CreateProcess() or some similar function. I have located the very instructive example of how to execute Notepad using CreateProcess() here in the forums. Unfortunatley, I can't make the same work with bmk. The following code generates "Not available". I assume that I do something wrong. If bmk executed I would expect at least some output. Documentation for FreeProcess is a bit sparse. Greatful for any help I can get.

Import PUB.FreeProcess

Local process:TProcess = CreateProcess( "C:\Program\BlitzMax\bin\bmk -a makemods pub.xmlmod" )

If ( process.pipe.ReadAvail() )
	Print "Available!"
Else
	Print "Not available"
End If



slenkar(Posted 2009) [#2]
have you tried running your app with a double-click to the executable?

Just a guess, dont know if it will work.


ziggy(Posted 2009) [#3]
Working example:
Import pub.FreeProcess

Local process:TProcess = CreateProcess("~qC:\BlitzMax\bin\bmk.exe~q makemods -a pub.directx",1)

While process.Status() = 1	'While process is working
	PrintTextFromProcess(process:TProcess)
	Delay(100)
Wend

PrintTextFromProcess(Process:TProcess)

End	'Done!



Function PrintTextFromProcess(Process:TProcess)

	
	If Process.pipe.ReadAvail() > 0 Then	'If the pipe has data
		StandardIOStream.WriteString(process.pipe.ReadString(process.pipe.ReadAvail()))	'We send the data as text to the standardiostream
		StandardIOStream.Flush()  'We flush the stream
	End If	

End Function


Notice the ~q in the executable name, just in case the path has white spaces. Also, the -a parameter goes AFTER the makemods. Additionally, I don't know where did you get a pub.xmlmod module, but I don't have it, so replaced it with the pub.directx module.
Then, to get the data from the process, we have to ensure the process is running, so we use a while loop, that executes while the process is running, checking if there is anything to send to the standard i/o stream. A Delay in the while loop could free some CPU time, wich is a good idea in a real scenario.

EDIT: Small fix applied.


JonasL(Posted 2009) [#4]
Thanks, ziggy! Your example really cleared things up. I'm just trying to do an automated build environment for some mods that are included in our framework. I guess I could have scripted it, but BMX is available on all platforms anyway, so it seemed like a good idea to use it as a scripting language as well.


TaskMaster(Posted 2009) [#5]
Your framework should probably not be putting mods in the pub.mod directory. You should put them in your own mod directory.


xlsior(Posted 2009) [#6]
What Taskmaster said.

Any Blitzmax update can/will remove 'custom' additions to the pub.mod and brl.mod folders, so they are bound to disappear on people.