Forum > General

process exeuction with interactive mode

(1/4) > >>

fpc2pas:
hey folks

i am trying to do something that i need for my project,  to use the code shared below to execute a command and keep waiting until the finish, and that works fine but what I need is to keep that process open and accept multiple commands maybe three, four ..etc


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function exec_hold(command:string):string;var  StartInfo: TStartupInfo;  ProcInfo: TProcessInformation;  CreateOk: boolean;  input: String;  path : String;  cmd : String;begin  { fill with known state }  FillChar(StartInfo, SizeOf(TStartupInfo), #0);  FillChar(ProcInfo, SizeOf(TProcessInformation), #0);  StartInfo.cb := SizeOf(TStartupInfo);   cmd := 'c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe';   input := '-command ' + command;  CreateOk := CreateProcess(PChar(cmd), PChar(input), nil, nil, false, CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil,     nil, StartInfo, ProcInfo);  { check to see if successful }  if CreateOk then     while WaitForSingleObject(ProcInfo.hProcess, INFINITE) = WAIT_TIMEOUT do    begin    // may or may not be needed. Usually wait for child processes   // WaitForMultipleObjects(ProcInfo.hProcess, INFINITE);    sleep(50);     end;end;  

Edson:
I recommend to use my library UnTerminal https://github.com/t-edson/UnTerminal.

It's a wrapper for TProccess that include events. Check the sample projects for a simple use.

fpc2pas:

--- Quote from: Edson on June 13, 2021, 10:48:00 pm ---I recommend to use my library UnTerminal https://github.com/t-edson/UnTerminal.

It's a wrapper for TProccess that include events. Check the sample projects for a simple use.

--- End quote ---

thanks but not sure that will work with console apps! have you done any demo with the console?

Edson:

--- Quote from: fpc2pas on June 14, 2021, 02:16:19 pm ---thanks but not sure that will work with console apps! have you done any demo with the console?

--- End quote ---

The sample projects, in Windows, use the CMD process to send "dir" command and interact with the shell.

I don't know what console App do you want to control. The Windows Powershell?

engkin:
Are you developing a console app, or are you controlling a console app, or maybe both?

Navigation

[0] Message Index

[#] Next page

Go to full version