capture standard io strangely ? fmc.PrcoessStream
BlitzMax Forums/BlitzMax Programming/capture standard io strangely ? fmc.PrcoessStream
| ||
Ok this is a tricky problem but... I currently have a seriously annoying problem with a program i am writting. Here is how it works. Executable called "installservice.exe" runs "installservice.exe" calls the NT command prompt "instsrv.exe" to install another nt exe called "srvany.exe". It then sets up the registry entries to run srvany.exe with a blitzmax compiled executable called peer.debug.exe. Once it is installed and the registry is updated, it calls "net start" to start the service. It does this all using FABIAN's CreateProcessStream fmc.PrcoessStream to read the ouput of said executables. NOW here is the problem: It will execute the programs fine. The first time it runs it will perform all things according to plan. All output gets directed properly and things work. Upon ending the installservice.exe program there will be a newly installed and running service written in blitzmax. If i run installservice.exe again the capture in/out from the process seems to randomly not work. IE it will work with some executables but not with others. I tracked it down that if I KILL srvany or peer.debug.exe from the process list, it will work again as planned. The idea of installservice.exe is to check to see if the service is installed. If not, install it. Then check to see if it is running. If not, start it. This weird behavior has lead me to believe that somewhere blitz is capturing the input / output in an odd manner. Anyone got any ideas ? Unfortunatly I cant post all the code, but this is installservice.exe 'this program will install the cap program as a service Framework BRL.FileSystem Import brl.standardio Import fmc.Processstream Import "../../../global/types/tcommandline.bmx" Import "../../../global/libs/registryfunctions.bmx" Local temp_action:String = GetCommand(0) Local temp_name:String = GetCommand(1) Local temp_read:String Local temp_ok:Int = True Local temp_stream:TProcessStream Select temp_action.tolower() Case "install" Local temp_path:String = RealPath(GetCommand(2)) If temp_name.length And temp_path.length And FileType(temp_path) = 1 temp_ok = False temp_stream = CreateProcessStream("instsrv.exe "+temp_name+" "+CurrentDir()+"/srvany.exe") If temp_stream While temp_stream.eof() = False temp_read = temp_stream.ReadLine() Select temp_read Case " CreateService SUCCESS at creating:" temp_ok = True Print "service installed" End Select Wend If temp_ok = True 'update the registry entries Local temp_reg:tregkey = OpenRegKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"+temp_name) If temp_reg temp_reg.close() temp_reg = CreateRegKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"+temp_name+"\Parameters") temp_reg.setstring("Application",temp_path) temp_reg.close() 'start the service temp_stream = CreateProcessStream("net start "+temp_name) temp_ok = False While temp_stream.eof() = False temp_read = temp_stream.ReadLine() Select temp_read Case "The "+temp_name+" service was started successfully." temp_ok = True Print "service started" Case "The requested service has already been started." temp_ok = True Print "service started" Case "The service name is invalid." temp_ok = False End Select Wend End If End If End If End If Case "remove" If temp_name.length 'stop the service temp_ok = False temp_stream = CreateProcessStream("net stop "+temp_name) While temp_stream.eof() = False Delay 1 temp_read = temp_stream.ReadLine() Select temp_read Case "The "+temp_name+" service is Not started." temp_ok = True Print "service stopped" Case "The "+temp_name+" service was stopped successfully." temp_ok = True Print "service stopped" Case "The specified service does not exist as an installed service." temp_ok = False End Select Wend 'uninstall service If temp_ok temp_ok = False temp_stream = CreateProcessStream("instsrv.exe "+temp_name+" remove") If temp_stream While temp_stream.eof() = False Delay 1 temp_read = temp_stream.ReadLine() Select temp_read Case "DeleteService SUCCESS" temp_ok = True Print "service removed" End Select Wend End If End If End If End Select |
| ||
Is this fmc.ProcessStream similar to Skid's Pub.FreeProcess (cross-platform and available through syncmods). If it does the same things (starting, terminating and reading output/writing input from/to processes) then I can vouch for its stability - I've been using it for many projects and never had strange results. I believe it is what the BlitzMax IDE uses too for talking to the compiler etc. If I've got the right idea, you may want to give that a try instead, unless of course there is a simple solution. ;-) |
| ||
Seb you do indeed have the correct idea. I tried pub.freeprocess but had to resort to using fabian's as there were issues with detecting when a process had ended, and capturing output! Got any examples you want to share, perhaps I was doing it wrong ? |