Bladeren bron

Added Process Detach/attach functions to FreeProcess. Updated FreeProcess documentation

Thomas Preece 9 jaren geleden
bovenliggende
commit
69972d2c69

+ 34 - 0
freeprocess.mod/doc/CreateProcess.bmx

@@ -0,0 +1,34 @@
+SuperStrict 
+
+Local status:Int
+
+'Start notepad program
+'By Default processes are attached to the program (they will automatically terminate when your program is closed)
+Local Process1:TProcess = CreateProcess("notepad.exe")
+
+Print("notepad started!")
+Delay(1000)
+
+
+'Check current status of notepad, 1 is running, 0 is closed
+status = ProcessStatus(Process1)
+If status = 1 Then 
+	Print("notepad still running")
+Else
+	Print("notepad has been closed")
+EndIf
+
+Delay(1000)
+
+'Close notepad
+TerminateProcess(Process1)
+
+status = ProcessStatus(Process1)
+If status = 1 Then 
+	Print("notepad still running")
+Else
+	Print("notepad has been closed")
+EndIf
+
+
+

+ 24 - 0
freeprocess.mod/doc/ProcessAttach.bmx

@@ -0,0 +1,24 @@
+SuperStrict 
+
+
+'Start notepad program
+'By Default processes are attached to the program (they will automatically terminate when your program is closed)
+Local AttachedProcess:TProcess = CreateProcess("notepad.exe")
+'Detach notepad process
+ProcessDetach(AttachedProcess)
+
+'Reattach notepad process
+ProcessAttach(AttachedProcess)
+
+Print("notepad started!")
+Delay(1000)
+
+'Create new calculator process and detach from program (will not close when you close your program)
+Local DetachedProcess:TProcess = CreateProcess("calc.exe")
+ProcessDetach(DetachedProcess)
+
+Print("calculator started!")
+Delay(1000)
+
+Print("Program ending, notepad should close with it, calculator should stay open")
+End 

+ 24 - 0
freeprocess.mod/doc/ProcessDetach.bmx

@@ -0,0 +1,24 @@
+SuperStrict 
+
+
+'Start notepad program
+'By Default processes are attached to the program (they will automatically terminate when your program is closed)
+Local AttachedProcess:TProcess = CreateProcess("notepad.exe")
+'Detach notepad process
+ProcessDetach(AttachedProcess)
+
+'Reattach notepad process
+ProcessAttach(AttachedProcess)
+
+Print("notepad started!")
+Delay(1000)
+
+'Create new calculator process and detach from program (will not close when you close your program)
+Local DetachedProcess:TProcess = CreateProcess("calc.exe")
+ProcessDetach(DetachedProcess)
+
+Print("calculator started!")
+Delay(1000)
+
+Print("Program ending, notepad should close with it, calculator should stay open")
+End 

+ 34 - 0
freeprocess.mod/doc/ProcessStatus.bmx

@@ -0,0 +1,34 @@
+SuperStrict 
+
+Local status:Int
+
+'Start notepad program
+'By Default processes are attached to the program (they will automatically terminate when your program is closed)
+Local Process1:TProcess = CreateProcess("notepad.exe")
+
+Print("notepad started!")
+Delay(1000)
+
+
+'Check current status of notepad, 1 is running, 0 is closed
+status = ProcessStatus(Process1)
+If status = 1 Then 
+	Print("notepad still running")
+Else
+	Print("notepad has been closed")
+EndIf
+
+Delay(1000)
+
+'Close notepad
+TerminateProcess(Process1)
+
+status = ProcessStatus(Process1)
+If status = 1 Then 
+	Print("notepad still running")
+Else
+	Print("notepad has been closed")
+EndIf
+
+
+

+ 34 - 0
freeprocess.mod/doc/TerminateProcess.bmx

@@ -0,0 +1,34 @@
+SuperStrict 
+
+Local status:Int
+
+'Start notepad program
+'By Default processes are attached to the program (they will automatically terminate when your program is closed)
+Local Process1:TProcess = CreateProcess("notepad.exe")
+
+Print("notepad started!")
+Delay(1000)
+
+
+'Check current status of notepad, 1 is running, 0 is closed
+status = ProcessStatus(Process1)
+If status = 1 Then 
+	Print("notepad still running")
+Else
+	Print("notepad has been closed")
+EndIf
+
+Delay(1000)
+
+'Close notepad
+TerminateProcess(Process1)
+
+status = ProcessStatus(Process1)
+If status = 1 Then 
+	Print("notepad still running")
+Else
+	Print("notepad has been closed")
+EndIf
+
+
+

+ 1 - 0
freeprocess.mod/doc/intro.bbdoc

@@ -0,0 +1 @@
+The BlitzMax freeprocess module lets you execute other programs

+ 48 - 3
freeprocess.mod/freeprocess.bmx

@@ -1,13 +1,17 @@
-
+Rem
+bbdoc: Process Management
+End Rem
 Module PUB.FreeProcess
 
-ModuleInfo "Version: 1.03"
+ModuleInfo "Version: 1.04"
 ModuleInfo "Framework: FreeProcess multi platform external process control"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Author: Simon Armstrong"
 ModuleInfo "Modserver: BRL"
 
+ModuleInfo "History: 1.04 Release"
+ModuleInfo "History: Added Documentation, Added Detach and Attach Process Functions"
 ModuleInfo "History: 1.03 Release"
 ModuleInfo "History: Changed fork() to vfork() and exit() to _exit() to fix more hangs."
 ModuleInfo "History: 1.02 Release"
@@ -127,7 +131,17 @@ Type TProcess
 	Field	handle
 	Field	pipe:TPipeStream
 	Field	err:TPipeStream
+	Field   detached:Int
 
+	Method Detach()
+		detached = True
+		Return 1
+	End Method
+	
+	Method Attach()
+		detached = False
+		Return 1
+	End Method
 	Method Status()
 		If handle 
 			If fdProcessStatus(handle) Return 1
@@ -166,6 +180,7 @@ Type TProcess
 		If Not p.handle Return Null
 		p.pipe=TPipeStream.Create(infd,outfd)
 		p.err=TPipeStream.Create(errfd,0)
+		p.detached = False 
 		If Not ProcessList ProcessList=New TList
 		ProcessList.AddLast p
 		Return p
@@ -183,21 +198,51 @@ Type TProcess
 	Function TerminateAll() NoDebug
 		If Not ProcessList Return
 		For Local p:TProcess=EachIn ProcessList
-			p.Terminate
+			If p.detached = False Then 
+				p.Terminate
+			EndIf
 		Next
 		ProcessList=Null
 	End Function
 	
 End Type
 
+Rem
+bbdoc: Creates a process
+returns: TProcess value
+End Rem
 Function CreateProcess:TProcess(cmd$,flags=0)
 	Return TProcess.Create(cmd,flags)
 End Function
 
+Rem
+bbdoc: Checks status of program
+returns: 1 - still running, 0 - no longer running
+End Rem
 Function ProcessStatus(process:TProcess)
 	Return process.Status()
 End Function
 
+Rem
+bbdoc: Detaches a process from program
+returns: 1
+End Rem
+Function ProcessDetach(process:TProcess)
+	Return process.Detach()
+End Function
+
+Rem
+bbdoc: Reattaches a process from program
+returns: 1
+End Rem
+Function ProcessAttach(process:TProcess)
+	Return process.Attach()
+End Function
+
+Rem
+bbdoc: End Process
+returns: 1 - successful, 0 - failed
+End Rem
 Function TerminateProcess(process:TProcess)
 	Return process.Terminate()
 End Function