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?

Guy
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
Guy,

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

Prog.asm


.386
.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

.data

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

.data?

buff db 512 dup(?)

.code

include Getcmdline.asm
start:
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
terminateapp:
pop edi
pop esi
invoke ExitProcess,0
error1:
invoke StdOut,ADDR errmsg
jmp terminateapp

END start


Getcmdline.asm


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
scan:
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
restart:
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
next_char:
inc edx
jmp restart
end_of_line:
mov byte PTR [edi],0
inc edi
jmp scan
finish:
ret

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

Thank you guys.

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