Posts: 1,769
Threads: 410
Joined: Feb 2003
is there a way to run the command window for RunConsole hidden or at least minimized?
thanks.
Posts: 12,097
Threads: 142
Joined: Dec 2002
With RunConsole no. And it cannot be modified to support that.
Function RunConsole2
;/
function# $cl [str&sout] [$curDir] [showState] ;;showState: 0 hidden, 1 normal, 2 min, 3 max, etc, like with ShowWindow
;Runs a console program, waits and captures its output.
;Returns its exit code.
;Error if the file does not exist or failed to run.
;Supports only executable files.
;You can use special folders in program's path and in curDir, but not in command line parameters.
;Don't call this function from a thread that needs to process messages, eg has a dialog.
;cl - program name or full path, followed by command line parameters.
;sout - str variable that receives the output. If omitted or 0, displays in the QM output pane.
;curDir - current directory for the program.
;showState - window show state. By default it is hidden.
;EXAMPLE
;if(RunConsole2("schtasks.exe /?")) end "failed"
str sout2; if(!&sout) &sout=sout2
SECURITY_ATTRIBUTES sa.nLength=sizeof(SECURITY_ATTRIBUTES)
sa.bInheritHandle=1
int cp(GetCurrentProcess) hOutput hStdOutputWritePipe hStdOutput hStdError hStdInput
CreatePipe(&hOutput &hStdOutputWritePipe &sa 0)
DuplicateHandle(cp hStdOutputWritePipe cp &hStdOutput 0 1 DUPLICATE_SAME_ACCESS)
DuplicateHandle(cp hStdOutput cp &hStdError 0 1 DUPLICATE_SAME_ACCESS)
DuplicateHandle(cp hStdOutput cp &hStdInput 0 1 DUPLICATE_SAME_ACCESS)
CloseHandle(hStdOutputWritePipe)
PROCESS_INFORMATION pi
STARTUPINFO si.cb = sizeof(STARTUPINFO)
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW
si.hStdInput = hStdInput
si.hStdOutput = hStdOutput
si.hStdError = hStdError
si.wShowWindow = showState
str s1.expandpath(cl) s2.expandpath(curDir)
int r=CreateProcess(0 s1 0 0 1 CREATE_NEW_CONSOLE 0 s2 &si &pi)
CloseHandle(hStdOutput)
CloseHandle(hStdError)
CloseHandle(hStdInput)
if(!r)
,CloseHandle(hOutput)
,end s1.dllerror
CloseHandle(pi.hThread)
;read
s1.all(64)
rep
,if(!ReadFile(hOutput s1 64 &_i 0)) break
,sout.geta(s1.lpstr 0 _i)
if(!GetExitCodeProcess(pi.hProcess &_i)) _i=-1000
CloseHandle(hOutput)
CloseHandle(pi.hProcess)
if(&sout=&sout2) out sout
ret _i
;INFO:
;This is from codeproject, 'Real-Time Console Output Redirection'.
;Also it is possible to get console output in real time, but needs an intermediate exe, which is provided with the code. It is 'rtconsole.exe', 4 kb. It also makes possible to use this on win9x with 16 bit programs.
Posts: 1,769
Threads: 410
Joined: Feb 2003
wow thanks!
i'm having problems trying to get xcopy to work though. here's what i'm using but i can't seem to get any info.
RunConsole2("xcopy.exe C:\qm\*.* F:\qm /c /v /i /k /h /m /y /z /exclude:c:\qm\excld.txt" _s "C:\WINDOWS\system32\")
am i doing something wrong here? it worked fine with runconsole.
Posts: 12,097
Threads: 142
Joined: Dec 2002
Posts: 1,769
Threads: 410
Joined: Feb 2003
indeed it does!!!
thanks!