Вниз
Скачать: CL | DM;

CreateProcess запуск cmd /c ...   Найти похожие ветки 

← →
Neo Trinitron ©   (2006-06-16 19:41) [0]

Нужно запустить 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. Что я не так делаю?


← →
Пусик ©   (2006-06-16 19:48) [1]

Сравни со своим кодом:

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;


← →
Neo Trinitron ©   (2006-06-16 20:07) [2]

Уже не ругается, но команда

"cmd /c ping 192.168.0.0 >file1.txt"

не хочет выводить инфу в файл...


← →
Пусик ©   (2006-06-16 20:23) [3]


> 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-19 11:22) [4]

Спасибо, всё получилось



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.029 c
1-1148925058
VitaWED
2006-05-29 21:50
2006.07.09
ListView + кнопки


2-1151101235
arturich
2006-06-24 02:20
2006.07.09
определение индекса строки по найденному слову


6-1141631672
Venchik
2006-03-06 10:54
2006.07.09
Delphi 7. Менеджер закачек. Выбор классов, компонент.


1-1148980769
Pavels
2006-05-30 13:19
2006.07.09
Плагинная архитектура приложения.


2-1150796160
TrainerOfDolphins
2006-06-20 13:36
2006.07.09
Cntrl+Delete –удаление записи через DBGrid




   Наверх