I'am using the example of Iczelion's tute21 to exectue a prog.

The prog I want to execute goes like this : prog.exe -d

I need to call the prog with prog.exe -d otherwise I get messages from the prog to enter the -d.

I've tried with crlf after prog.exe -d and number of diffrents syntax but no result.

Is there a way to send two commands to CreateProcess and then get the answer from the command line?

Posted on 2004-12-07 07:36:51 by Guy
Assuming I'm understanding you correctly, you need to use pipes for this. Reference Creating a Child Process with Redirected Input and Output in the Platform SDK to see how it's done in C. By redirecting stdin, stdout, and stderr to pipes you are able to write to stdin and read from stdout/stderr. Porting the code to assembly is fairly straight forward.
Posted on 2004-12-07 10:51:06 by nohaven

Here is a small console demo application expecting for the command line parameter -d


.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib


message db 'Program terminated normally',0
errmsg db 'prog -d',0


buff db 512 dup(?)


include Getcmdline.asm
push esi
push edi
mov esi,OFFSET buff
invoke ParseCmdLine,esi
cmp eax,2 ; eax holds the number of cmdline params
; if no any params then exit
jne error1
mov edi,dword PTR [esi+4] ; dword PTR [esi] = pointer to app name
; dword PTR [esi+4] = pointer to param1
; dword PTR [esi+8] = pointer to param2 etc.
cmp word PTR [edi],'d-'
jne error1
invoke StdOut,ADDR message
pop edi
pop esi
invoke ExitProcess,0
invoke StdOut,ADDR errmsg
jmp terminateapp

END start


ParseCmdLine PROC uses esi edi buffer:DWORD

invoke GetCommandLine
lea edx,[eax-1]
xor eax,eax
mov esi,buffer
lea edi,[esi+256]
mov ch,32
inc edx
mov cl,byte PTR [edx]
or cl,cl
jz finish
cmp cl,32
je scan

inc eax
mov dword PTR [esi],edi
add esi,4
mov cl,byte PTR [edx]
or cl,cl
jz finish
cmp cl,ch
je end_of_line
cmp cl,34
jne @f
xor ch,32
jmp next_char
mov byte PTR [edi],cl
inc edi
inc edx
jmp restart
mov byte PTR [edi],0
inc edi
jmp scan

ParseCmdLine ENDP
Posted on 2004-12-07 12:38:48 by Vortex
I got it.

Thank you guys.

Posted on 2004-12-07 15:17:35 by Guy