How do you get pub.freeprocess to read i/o ??

BlitzMax Forums/BlitzMax Programming/How do you get pub.freeprocess to read i/o ??

LOL - that's really strange. I just posted like I normally do! Hopefully a moderator can clean this little problem up.

Anyways, I think the pause could be partly because of the fact that IpConfig seems to output it's title, then gather the info, then output it, and depending on your hardware, it can take a few seconds delay.

However, my second method works fine on my end too. I think the idea is to grab all the data that's available when you loop (using ReadPipe() ) as oppose to line by line as it's slower.

Also, there is a inbuilt function that converts byte arrays into string, so the whole process can be done on one line:

SuperStrict

Framework brl.standardio
Import pub.freeprocess

?Win32

	'Lets use OO for the hell of it, although you can use CreateProcess() if you prefer
	'There is only 1 flag available - HIDECONSOLE that is supposed to hide console output ;-) but it doesn't make much difference either way on my Windows machine
	Local temp_process:TProcess = TProcess.Create("ipconfig",HIDECONSOLE)
	
	Print ""
	Print "IPConfig Status: " + temp_process.Status()	'Show that the program is running
	Print "================================"
	
	While temp_process.Status()	'Checks to see if the process is still running
		
		'Temp variable that stores output from the pipe before it is converted to a string
		Local tmpBytes:Byte[]
		'Check if the pipe contains any data that hasn't been read and if so, load data into variable array, and convert array to string
		If temp_process.pipe.ReadAvail() Then tmpBytes = temp_process.pipe.ReadPipe();Print String.FromBytes( Varptr tmpBytes[0], tmpBytes.length )
		
	Wend
		
	'Terminate process manually (the fact that is has escaped the above loop means it has already closed but put it in as an example)
	temp_process.Close()
	'This is a quick way you can terminate all processes without bothering to loop through them all (again not needed)
	TProcess.TerminateAll()
	
	Print "================================"
	Print "IPConfig Status: " + temp_process.Status()	'Show that the program has ended
	Print ""

?MacOs

	Print "Mac OS X doesn't have IpConfig."

?Linux

	Print "Linux doesn't have IpConfig."

?