Главная страница
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.049 c
15-1149787637
Тот же самый
2006-06-08 21:27
2006.07.09
Linux must die


15-1149836328
ANB
2006-06-09 10:58
2006.07.09
Как красивее и понятнее ?


2-1150635281
antoxa2005
2006-06-18 16:54
2006.07.09
Интересно почему, Если в IBDataBase.DatebaseName:= Comp1 d mybd.


4-1143729890
Lik
2006-03-30 18:44
2006.07.09
Проблема с RasEnumConnections


2-1150627340
DPOBOCEK
2006-06-18 14:42
2006.07.09
Помогите с указателями плз...