MattO
27th June 2002, 21:37
Hello All,
This is my first post ;)
I trying to learn delphi whilst writing an application.
I have used the widely available 'WinExecAndWait' routine to successfully run console programs; vStrip, Azid etc.
My problem is I want to create a text file of vStrip's output.
I know at the DOS prompt I can achieve this with:
vstrip.exe movie.vob>info.txt
But using this type of line in my program with 'WinExecAndWait', my program always reports an error 'Cannot find info.txt'.
Does anyone know how to use this DOS line in Delphi?
Also, how do I get the AV delay figure into Delphi? vStrip reports the delay figure in its ripping output, but how can I get this figure into Delphi? (I am using the EXE's not DLL's)
Thanks for any help.
MattO
TheWEF
30th June 2002, 23:28
hi mattO!
you have to use pipes.
this is the code i use in gknot to read and analyze azid.exe output for 2-pass azid audio decoding. you should be able to modify it for your needs:
// azid test
// written by aquaplaning and TheWEF
// function to find the maximum gain value for
// azid ac3 -> wav decoding.
// aCmdLine = 'x:\path\azid.exe <other options> -g 30dB -N "x:\path\name.ac3"'
function TEncoder.azidTest(const aCmdLine: String;var maximumG:single): boolean;
const
ReadBuffer = 200000;
var
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
Security : TSecurityAttributes;
CTOuts: TCommTimeOuts;
OutReadPipe, OutWritePipe :THandle;
InReadPipe, InWritePipe :THandle;
ErrorReadPipe,ErrorWritePipe :THandle;
Buffer, ErrBuffer :PChar;
BytesRead, ErrBytesRead, bufferbegin :DWord;
BytesToRead :DWord;
BytesToParse,i :integer;
wert :single;
ProcessStatus :DWord;
res, ReadPipeOK,ReadErrPipeOK :boolean;
PipeEmpty, ErrPipeEmpty :boolean;
BothPipesEmpty :boolean;
Wait_ms :integer;
procedure ParseValues;
var
count:integer;
begin
i:=BytesToParse;
while (i > 0) and (ErrBuffer[i] <> ')') do dec(i,1);
if i>0 then
begin
bufferbegin:=BytesToParse-i;
BytesToParse:=i;
end
else
begin
bufferbegin :=0;
end;
i := BytesToParse;
while i >5 do
begin
if ((Buffer[i] = ')')and (Buffer[i-1] = 'B')) then
begin
Dec(i,3);
wert := (Byte(Buffer[i]) - 48) / 10;
dec(i);
if (Buffer[i]='.') then
begin
dec(i);
wert := wert + (Byte(Buffer[i]) - 48);
dec(i);
if (Buffer[i]<>'+') then wert := wert + (Byte(Buffer[i]) - 48)*10;
end;
if wert<=azidTestdB then maximumG := Max(maximumG,wert);
end;
Dec(i);
end;
if bufferbegin>0 then
begin
for count:=0 to bufferbegin-1 do
begin
buffer[i]:=buffer[BytesToParse+i];
end;
end;
end;
procedure FindLastPercEntry;
begin
i:=ErrBytesRead;
while (i > 0) and (ErrBuffer[i] <> '%') do dec(i,1);
if i>4 then
begin
dec(i,3);
perc := (Byte(ErrBuffer[i]) - 48);
dec(i,1);
if ErrBuffer[i]<>' ' then
Inc(perc,(Byte(ErrBuffer[i]) - 48)*10);
end;
end;
begin
Result := False;
perc:=0;
With Security do
begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
With CTOuts do
begin
ReadIntervalTimeout :=0;
ReadTotalTimeoutMultiplier :=0;
ReadTotalTimeoutConstant :=10;
WriteTotalTimeoutMultiplier :=0;
WriteTotalTimeoutConstant :=0;
end;
if not Createpipe(InReadPipe, InWritePipe, @Security,0) then
begin
LogMsg('ERROR: CreateInPipe failed.');
Exit;
end;
if not Createpipe(OutReadPipe, OutWritePipe, @Security, ReadBuffer + 1) then
begin
LogMsg('ERROR: CreateOutPipe failed.');
Exit;
end;
if not Createpipe(ErrorReadPipe, ErrorWritePipe, @Security, ReadBuffer*2 + 1) then
begin
LogMsg('ERROR: CreateErrorPipe failed.');
Exit;
end;
SetCommTimeouts(InReadPipe,CTOuts);
SetCommTimeouts(InWritePipe,CTOuts);
SetCommTimeouts(OutReadPipe,CTOuts);
SetCommTimeouts(OutWritePipe,CTOuts);
SetCommTimeouts(ErrorReadPipe,CTOuts);
SetCommTimeouts(ErrorWritePipe,CTOuts);
FillChar(StartupInfo, SizeOf(TStartupInfo), #0);
with StartupInfo do
begin
hStdOutput := OutWritePipe;
hStdInput := InReadPipe;
hStdError := ErrorWritePipe;
cb:= SizeOf(TStartupInfo);
dwFlags:= STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
wShowWindow:= SW_HIDE;
end;
Buffer := AllocMem(ReadBuffer + 1);
ErrBuffer := AllocMem(ReadBuffer + 1);
Res := CreateProcess(nil, PChar(aCmdLine), @Security, nil, True,
IDLE_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
maximumG := 0;
PipeEmpty :=True;
ErrPipeEmpty :=True;
if Res then
begin
Synchronize(azidTest_CreatePercLog);
LogLine('Process created. Searching...');
EncoderProcess:=ProcessInfo;
bufferbegin := 0;
BytesRead :=0;
ErrBytesRead :=0;
BytesToRead:=ReadBuffer;
Wait_ms:=100;
Repeat
if (((BytesRead=BytesToRead) or (ErrBytesRead=ReadBuffer)) and (Wait_ms>1)) then Wait_ms:=Wait_ms div 2;
BytesRead :=0;
ErrBytesRead :=0;
ProcessStatus :=0;
BytesToRead :=ReadBuffer - bufferbegin;
WaitForSingleObject(ProcessInfo.hProcess, Wait_ms);
ReadPipeOK:=PeekNamedPipe(OutReadPipe,nil,ReadBuffer,nil,@BytesRead,nil);
if (ReadPipeOK and (BytesRead>0)) then
ReadPipeOK := ReadFile(OutReadPipe, Buffer[bufferbegin],BytesToRead, BytesRead, nil)
else
BytesRead:=0;
ReadErrPipeOK:=PeekNamedPipe(ErrorReadPipe,nil,ReadBuffer,nil,@ErrBytesRead,nil);
if (ReadErrPipeOK and (ErrBytesRead>0)) then
ReadErrPipeOK:= ReadFile(ErrorReadPipe, ErrBuffer[0],ReadBuffer, ErrBytesRead, nil)
else
ErrBytesRead:=0;
BytesToParse:=bufferbegin+BytesRead*Integer(ReadPipeOK);
PipeEmpty:=(BytesToParse=0);
ErrPipeEmpty:=((ErrBytesRead*Integer(ReadPipeOK))=0);
if not PipeEmpty then ParseValues;
if not ErrPipeEmpty then FindLastPercEntry;
Synchronize(azidTest_PrintPercLog);
GetExitCodeProcess(ProcessInfo.hProcess,ProcessStatus);
until (ProcessStatus <> STILL_ACTIVE) and PipeEmpty and ErrPipeEmpty;
Result:= True;
Synchronize(azidTest_DeletePercLog);
end
else
LogMsg('ERROR: Azid: Createprocess failed.');
FreeMem(Buffer);
FreeMem(ErrBuffer);
CloseHandle(InReadPipe);
CloseHandle(InWritePipe);
CloseHandle(OutReadPipe);
CloseHandle(OutWritePipe);
CloseHandle(ErrorReadPipe);
CloseHandle(ErrorWritePipe);
end;
MattO
1st July 2002, 20:30
Wooow!
I'll see if I can understand it, I am very much a Delphi novice ;)
thanks, The WEF.
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.