![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
CreateProcess запуск cmd /c ... [D6, 2000]
Neo Trinitron © (2006-06-16 19:41:00)Нужно запустить cmd /c ping 192.168.0.0
мой код:
if CreateProcess(0,
PChar('cmd /c ping 192.168.0.0'),
0,
0,
true,
NORMAL_PRIORITY_CLASS,
0,
0,
StInfo,
Prc)
выдайт Access Violation. Что я не так делаю?
Neo Trinitron (2006-06-19 11:22:00) [1]Спасибо, всё получилось
Пусик (2006-06-16 20:23:00) [2]
> Neo Trinitron © (16.06.06 20:07) [2]
Замени блок:
function ExecCmd(const aCommand,aPath: String;const aShow, aWaitExit: Boolean): Boolean;
var
pi:PROCESS_INFORMATION;
si:STARTUPINFO;
cmdLine,Path: String;
begin
ZeroMemory(@si,sizeof(si));
si.cb:=SizeOf(si);
si.dwFlags := STARTF_FORCEONFEEDBACK+STARTF_USESHOWWINDOW;
if aShow then si.wShowWindow := SW_SHOWNORMAL else si.wShowWindow := SW_HIDE;
Path := aPath;
cmdLine := aCommand;
Вызов:
ExecCmd('c:\winnt\system32\cmd.exe /c ping.exe 192.168.0.1>c:\file1.txt','c:\winnt\system32\',true,true);
Neo Trinitron (2006-06-16 20:07:00) [3]Уже не ругается, но команда
'cmd /c ping 192.168.0.0 >file1.txt'
не хочет выводить инфу в файл...
Пусик (2006-06-16 19:48:00) [4]Сравни со своим кодом:
function ExecCmd(const aCommand: String;const aShow, aWaitExit: Boolean): Boolean;
var
pi:PROCESS_INFORMATION;
si:STARTUPINFO;
cmdLine,Path: String;
begin
ZeroMemory(@si,sizeof(si));
si.cb:=SizeOf(si);
si.dwFlags := STARTF_FORCEONFEEDBACK+STARTF_USESHOWWINDOW;
if aShow then si.wShowWindow := SW_SHOWNORMAL else si.wShowWindow := SW_HIDE;
Path := ExtractFilePath(aCommand);
cmdLine := aCommand;
Result :=
CreateProcess( nil
PChar(cmdLine),
nil,
nil,
False,
0,
nil,
PChar(Path),
si,
pi );
if Result then
begin
CloseHandle(pi.hThread);
if aWaitExit then WaitForSingleObject( pi.hProcess, infinite );
CloseHandle(pi.hProcess);
end;
end;