Главная страница
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.034 c
3-1147339500
Юран
2006-05-11 13:25
2006.07.09
ПРОБЛЕМА С ПРОГОЙ


2-1150414507
GodsKeeper
2006-06-16 03:35
2006.07.09
Народ спасайте, диплом горит.


2-1150387058
Тимофей Юрьевич
2006-06-15 19:57
2006.07.09
лохонулся,как быть с формой


6-1141079808
Кефир87
2006-02-28 01:36
2006.07.09
HTTP метод POST принцип отправки данных


1-1148562932
Silver...
2006-05-25 17:15
2006.07.09
OLEContainer -> PowerPoint + ...??? Команды ???... = Типа Preview