CreateProcess not working properly on OS X

BlitzMax Forums/BlitzMax Beginners Area/CreateProcess not working properly on OS X

Justus(Posted 2009) [#1]
Hello,

I am trying to work with the data returned by the nslookup tool. If I start it by typing "nslookup blitzforum.de" into my OS X Terminal, it works just fine - just as good as when I start it with system_().

But since I need the result in my program, I need to use the pub.freeprocess module and TProcess to read it.

On Windows it works just fine, like in this example:

Local str:String = "nslookup blitzforum.de"

Local process:TProcess = CreateProcess(str, SHOWCONSOLE)

While Not KeyHit( KEY_ESCAPE )

If Process.err.ReadAvail() Or Process.pipe.ReadAvail() Then

linepipe:String = process.pipe.ReadLine().Trim()
lineerro:String = process.err.ReadLine().Trim()

If linepipe <> "" Then
Print linepipe

EndIf
If lineerro <> "" Then
Print lineerro

EndIf
EndIf


Wend


The exact same code does not return anything on OS X though. How's that?

Best regards,
Justus


skidracer(Posted 2009) [#2]
From memory, you need to supply a full path to the nslookup command.


Justus(Posted 2009) [#3]
Sounded good to me, too. Pity that

process:TProcess = CreateProcess("/usr/bin/nslookup dmoz.de",SHOWCONSOLE)

While line:String = process.pipe.ReadLine()
	Print line
Wend


does not work either.

If I call the command with system_ it works just fine, but then I can't access its return.
And if I check the status with process.Status it shows me a 1 for a couple of ms, so it seems like the program is indeed started.


Brucey(Posted 2009) [#4]
This seems to work (OS X 10.6, BMX 1.36) , except that it won't exit via escape (because polled input doesn't work like that on Mac).
SuperStrict

Framework brl.standardio
Import pub.freeprocess
Import BRL.PolledInput

Local str:String = "nslookup blitzforum.de"

Local process:TProcess = CreateProcess(str, 0)
Local linepipe:String
Local lineerro:String

While Not KeyHit( KEY_ESCAPE )

	If Process.err.ReadAvail() Then
		Local erroByte:Byte = process.err.ReadByte()
		If erroByte <> 10 Then
			lineerro:+ Chr(erroByte)
		Else
			Print lineerro
			lineerro = ""
		End If
	End If
	
	If Process.pipe.ReadAvail() Then

		Local pipeByte:Byte = process.pipe.ReadByte()
		If pipeByte <> 10 Then
			linepipe:+ Chr(pipeByte)
		Else
			Print linepipe
			linepipe = ""
		End If

	EndIf

Wend


... and I'm not sure how to tell if the process is finished or not. Status() always seems to return zero ?