I use multiple instances of a console program to interact with a server. I have automated many of the tasks with scripts. While these scripts are executing, lots of flicker and all the text is scrolling down the screen. I execute the app from withwin my program via shell. Is it possible to run a console program in a invisible window?
your suggestions are very appreciated :shock:
Klod
your suggestions are very appreciated :shock:
Klod
The code and ideas you're searching for are inside this proc:
Basically, you use CreatePipe, and send this for the app to write into or read from.
BatchProcess proc uses ebx ecx edx FormatString
local hRead,hWrite,bytesRead,thisProcess,HasErrors,HasWarnings
local startupinfo:STARTUPINFO,pinfo:PROCESS_INFORMATION,sat:SECURITY_ATTRIBUTES
local buffer[1024]:byte
invoke ShowCompilationWindow
mov HasErrors,0
mov HasWarnings,0
mov ecx,FormatString
.while byte ptr
.if word ptr=="1%"
mov word ptr,"s%"
.endif
inc ecx
.endw
invoke wsprintf,addr buffer,FormatString,addr ProjectName,addr ProjectName,addr ProjectName
;---------[ check if it's to copy file ]-----------------------------\
lea eax,buffer
.if dword ptr=='ypoc' && byte ptr==32 ; if command begins with "copy "
add eax,5
.while byte ptr && byte ptr!=32
inc eax
.endw
.if byte ptr==0
msgbox "File copy no destination specified!"
mov HasErrors,1 ; no destination specified
jmp _done
.endif
mov byte ptr,0
inc eax
invoke CopyFile,addr buffer[5],eax,0
.if !eax
print "Could not copy file"
.endif
jmp _done
.endif
;------------------------------------------------------------------/
mov sat.nLength,sizeof SECURITY_ATTRIBUTES
mov sat.lpSecurityDescriptor,NULL
mov sat.bInheritHandle,TRUE
invoke CreatePipe,addr hRead,addr hWrite,addr sat,NULL
.if eax==NULL
msgbox "Can't create pipe. Reboot PC!"
xor eax,eax
ret
.endif
mov startupinfo.cb,sizeof STARTUPINFO
invoke GetStartupInfo,addr startupinfo
mov eax,hWrite
mov startupinfo.hStdOutput,eax
mov startupinfo.hStdError,eax
mov startupinfo.dwFlags,STARTF_USESHOWWINDOW+STARTF_USESTDHANDLES
mov startupinfo.wShowWindow,SW_HIDE
;invoke MessageBox,hwndEdit,addr buffer,addr ProjectName,0
invoke CreateProcess,0,addr buffer,0,0,1,HIGH_PRIORITY_CLASS,0,0,addr startupinfo,addr pinfo
mov thisProcess,eax
.if !eax
invoke wsprintf,addr buffer,CTEXT("can't execute this command:",13,10,"%s"),FormatString
invoke MessageBox,hwndEdit,addr buffer,CTEXT("Batch compilation error"),MB_ICONERROR
xor eax,eax
ret
.endif
invoke CloseHandle,hWrite
.while TRUE
lea edi,buffer
mov ecx,1024/4
xor eax,eax
rep stosd
invoke ReadFile,hRead,addr buffer,1023,addr bytesRead,0
.if eax==NULL
invoke SendMessage,compWin_hWnd,EM_SETSEL,-1,0
invoke SendMessage,compWin_hWnd,EM_REPLACESEL,0,CTEXT(13,10)
invoke SendMessage,compWin_hWnd,EM_SETSEL,-1,0
.break
.else
invoke uInStrI,addr buffer,CTEXT("error")
.if eax
mov HasErrors,1
.endif
invoke uInStrI,addr buffer,CTEXT(" warning ")
.if eax
mov HasWarnings,1
.endif
invoke SendMessage,compWin_hWnd,EM_SETSEL,-1,0
invoke SendMessage,compWin_hWnd,EM_REPLACESEL,0,addr buffer
.endif
.endw
invoke CloseHandle,hRead
_done:
.if !HasErrors && !HasWarnings
invoke ShowWindow,compWin_hWnd,SW_HIDE
.endif
mov eax,HasErrors
xor eax,1
ret
BatchProcess endp
Basically, you use CreatePipe, and send this for the app to write into or read from.
Here's a standalone proc in C, that retrieves text, outputtedin stdout and stderr from a program you execute
char* uSysExecute2(const char* pExeName,const char* params){
SECURITY_ATTRIBUTES sat = {sizeof(SECURITY_ATTRIBUTES),0,true};
HANDLE hRead,hWrite;
if(!CreatePipe(&hRead,&hWrite,&sat,0)){
print("no pipe");
return 0;
}
STARTUPINFO info;
info.cb=sizeof(info);
GetStartupInfo(&info);
info.hStdOutput=hWrite;
info.hStdError=hWrite;
info.dwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
info.wShowWindow=SW_HIDE;
PROCESS_INFORMATION pinfo;
char* cmdline = ustrmix(pExeName," ",params);
if(!CreateProcess(0,cmdline,0,0,1,NORMAL_PRIORITY_CLASS,0,0,&info,&pinfo)){
prints("Error executing process:");
prints(cmdline);
xfree(cmdline);
return 0;
}
xfree(cmdline);
CloseHandle(hWrite);
char* result=(char*)xmalloc(1); int resultLen=0;
char tmp[512];
for(;;){
DWORD numbytes;
memclear(tmp,sizeof(tmp));
if(!ReadFile(hRead,tmp,sizeof(tmp)-1,&numbytes,0))break;
int tmplen = ustrlen(tmp);
result = (char*)xresize(result,resultLen+tmplen+1);
ustrcpy(result+resultLen,tmp);
resultLen+=tmplen;
}
CloseHandle(hRead);
return result;
}
Hi Ultrano
Thanks for your reply
This should be enough to to send me down the right path. I will have to brush up on pipes, since its quite some time that I played around with it.
Thanks
Klod
Thanks for your reply
This should be enough to to send me down the right path. I will have to brush up on pipes, since its quite some time that I played around with it.
Thanks
Klod