Need Help with KillProgram Process Command
Posted: Sat Jul 17, 2021 6:08 pm
Hi Folks,
I'm trying to use the KillProgram command to kill a process I deliberately left open, but it's not working. I know I'm doing something wrong.
Can someone please tell me where I'm messing up?
Thanks.
I'm trying to use the KillProgram command to kill a process I deliberately left open, but it's not working. I know I'm doing something wrong.
Can someone please tell me where I'm messing up?
Thanks.
Code: Select all
Define iI.i
Define sProgramOutput.s
Procedure.s RunExternalProgram(sPathExecutable.s, sWorkingDirectory.s, sParameter.s, *iExitCode1.integer)
Protected iRunResultCode.i, iKillResultCode.i = 0
Protected sLineFeed.s, sOutput.s
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
sLineFeed = #CR$ + #LF$
CompilerDefault
sLineFeed = #LF$
CompilerEndSelect
Debug sPathExecutable
Debug sWorkingDirectory
Debug sParameter
iRunResultCode = RunProgram(sPathExecutable, sParameter, sWorkingDirectory, #PB_Program_Open | #PB_Program_Read | #PB_Program_Error) ; #PB_Program_Wait
iMDL_UI_Process_ID = -1
sOutput = ""
If iRunResultCode
While ProgramRunning(iRunResultCode)
If AvailableProgramOutput(iRunResultCode)
sOutput = sOutput + ReadProgramString(iRunResultCode) + sLineFeed
EndIf
Wend
sOutput = sOutput + sLineFeed + sLineFeed
sOutput = sOutput + "Exit Code: " + Str(ProgramExitCode(iRunResultCode)) + sLineFeed
KillProgram(iRunResultCode)
Debug "Ran Kill command!"
CloseProgram(iRunResultCode) ; Close the connection to the program
EndIf
*iExitCode1\i = iRunResultCode
ProcedureReturn sOutput
EndProcedure
sProgramOutput = RunExternalProgram("cmd.exe", "C:\Windows\", " /K for %c in (C:\Windows\*.*) do echo " + Chr(34) + "%c" + Chr(34), @iI)
Debug "Return code is: " + iI
Debug "Program output = " + sProgramOutput
End