Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.07.09;
Скачать: 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 вся ветка

Текущий архив: 2006.07.09;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.043 c
2-1151044392
Demand
2006-06-23 10:33
2006.07.09
Окна


2-1150797351
Unknowing
2006-06-20 13:55
2006.07.09
Файлы данных


2-1150720795
AlexanderMS
2006-06-19 16:39
2006.07.09
Вопросик про шрифт


2-1150976741
Tochka
2006-06-22 15:45
2006.07.09
Выключение комьпютера


11-1129737524
thaddy
2005-10-19 19:58
2006.07.09
Worse, it is a general bug!