Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

izlaz iz shellexecute u fajl

[es] :: Pascal / Delphi / Kylix :: izlaz iz shellexecute u fajl

[ Pregleda: 2401 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Milos Sreckovic
System administrator, SET d.o.o.
Šabac

Član broj: 30126
Poruke: 267
212.62.46.*

Sajt: www.set.rs


+2 Profil

icon izlaz iz shellexecute u fajl23.08.2006. u 11:24 - pre 215 meseci
ShellExecute(FBackUp.Handle,
nil,
'Z:\lista\dar\dar.exe','-x "citaj a\posta-2006-08-23" -g "POSTA ZA SLANJE/tanja/bbkink/picture/1992 BLUES ON THE BAYON .jpg" -f -O',
'Z:\lista\dar\',
SW_SHOW);

ovo je naredma koja uspesno radi, samo ona nesto ispisuje u cmd a meni treba da to stavim u fajl. kada je direktno pokrenem u cmd samo stavim "> a.txt" i to je to, ali ne znam sta ovde da uradim?
nece da na kraju parametara samo stavim "> a.txt".
 
Odgovor na temu

savkic
Igor Savkić

Moderator
Član broj: 92186
Poruke: 2739



+92 Profil

icon Re: izlaz iz shellexecute u fajl23.08.2006. u 14:16 - pre 215 meseci
> ovo je naredma koja uspesno radi, samo ona nesto ispisuje u cmd a meni treba da to stavim u fajl. kada
> je direktno pokrenem u cmd samo stavim "> a.txt" i to je to, ali ne znam sta ovde da uradim?

Biće ti najlakše da iskoristiš JCL funkcije WinExec32AndRedirectOutput ili CreateDOSProcessRedirected.
 
Odgovor na temu

Milos Sreckovic
System administrator, SET d.o.o.
Šabac

Član broj: 30126
Poruke: 267
212.62.46.*

Sajt: www.set.rs


+2 Profil

icon Re: izlaz iz shellexecute u fajl24.08.2006. u 12:05 - pre 215 meseci
i jedna i druga mi izbacuje gresku kao sto je na slici

evo koda i ijedne i druge

Code:

createDOSProcessRedirected('Z:\lista\dar\dar.exe -x "citaj a\posta-2006-08-23" -g "POSTA ZA SLANJE/tanja/bbkink/picture/1992 BLUES ON THE BAYON .jpg" -f -O','Z:\lista\dar\a.txt','Z:\lista\dar\OutPut.txt','Please, record this message')

WinExec32AndRedirectOutput('Z:\lista\dar\dar.exe -x "citaj a\posta-2006-08-23" -g "POSTA ZA SLANJE/tanja/bbkink/picture/1992 BLUES ON THE BAYON .jpg" -f -O',a)
Prikačeni fajlovi
 
Odgovor na temu

Milos Sreckovic
System administrator, SET d.o.o.
Šabac

Član broj: 30126
Poruke: 267
212.62.46.*

Sajt: www.set.rs


+2 Profil

icon Re: izlaz iz shellexecute u fajl24.08.2006. u 12:38 - pre 215 meseci
ok to sam sredi, sad kad pokrenem createDOSProcessRedirected onda mi zakuca... Posto nisam nasao nikakav unit sa ovom funkcijom, direktno sam je kopirao u moj i izglda ovako

Code:

function CreateDOSProcessRedirected(const CommandLine, InputFile, OutputFile, ErrMsg :string):boolean;
const
  ROUTINE_ID = '[function: CreateDOSProcessRedirected ]';
var
  OldCursor     : TCursor;
  pCommandLine  : array[0..MAX_PATH] of char;
  pInputFile,
  pOutPutFile   : array[0..MAX_PATH] of char;
  StartupInfo   : TStartupInfo;
  ProcessInfo   : TProcessInformation;
  SecAtrrs      : TSecurityAttributes;
  hAppProcess,
  hAppThread,
  hInputFile,
  hOutputFile   : THandle;
begin

  Result := False;

  { check for InputFile existence }
  if not FileExists(InputFile)
  then
    raise Exception.CreateFmt(ROUTINE_ID          + #10 +  #10 +
                              'Input file * %s *' + #10 +
                              'does not exist'    + #10 +  #10 +
                              ErrMsg, [InputFile]);

  { save the cursor }
  OldCursor     := Screen.Cursor;
  Screen.Cursor := crHourglass;

  { copy the parameter Pascal strings to null terminated strings }
  StrPCopy(pCommandLine, CommandLine);
  StrPCopy(pInputFile, InputFile);
  StrPCopy(pOutPutFile, OutputFile);

  TRY

    { prepare SecAtrrs structure for the CreateFile calls
      This SecAttrs structure is needed in this case because
      we want the returned handle can be inherited by child process
      This is true when running under WinNT.
      As for Win95 the documentation is quite ambiguous }
    FillChar(SecAtrrs, SizeOf(SecAtrrs), #0);
    SecAtrrs.nLength              := SizeOf(SecAtrrs);
    SecAtrrs.lpSecurityDescriptor := nil;
    SecAtrrs.bInheritHandle       := True;

    { create the appropriate handle for the input file }
    hInputFile := CreateFile(
                             pInputFile,                            { pointer to name of the file }
                             GENERIC_READ or GENERIC_WRITE,         { access (read-write) mode }
                             FILE_SHARE_READ or FILE_SHARE_WRITE,   { share mode }
                             @SecAtrrs,                             { pointer to security attributes }
                             OPEN_ALWAYS,                           { how to create }
                             FILE_ATTRIBUTE_TEMPORARY,              { file attributes }
                             0 );                                   { handle to file with attributes to copy }


    { is hInputFile a valid handle? }

    if hInputFile = INVALID_HANDLE_VALUE
    then
      raise Exception.CreateFmt(ROUTINE_ID                                                     + #10 +  #10 +
                                'WinApi function CreateFile returned an invalid handle value'  + #10 +
                                'for the input file * %s *'                                    + #10 + #10 +
                                ErrMsg, [InputFile]);

    { create the appropriate handle for the output file }
    hOutputFile := CreateFile(
                              pOutPutFile,                           { pointer to name of the file }
                              GENERIC_READ or GENERIC_WRITE,         { access (read-write) mode }
                              FILE_SHARE_READ or FILE_SHARE_WRITE,   { share mode }
                              @SecAtrrs,                             { pointer to security attributes }
                              CREATE_ALWAYS,                         { how to create }
                              FILE_ATTRIBUTE_TEMPORARY,              { file attributes }
                              0 );                                   { handle to file with attributes to copy }

    { is hOutputFile a valid handle? }

    if hOutputFile = INVALID_HANDLE_VALUE
    then
      raise Exception.CreateFmt(ROUTINE_ID                                                     + #10 +  #10 +
                                'WinApi function CreateFile returned an invalid handle value'  + #10 +
                                'for the output file * %s *'                                   + #10 + #10 +
                                ErrMsg, [OutputFile]);

    { prepare StartupInfo structure }
    FillChar(StartupInfo, SizeOf(StartupInfo), #0);
    StartupInfo.cb          := SizeOf(StartupInfo);
    StartupInfo.dwFlags     := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
    StartupInfo.wShowWindow := SW_HIDE;
    StartupInfo.hStdOutput  := hOutputFile;
    StartupInfo.hStdInput   := hInputFile;

    { create the app }
    Result := CreateProcess(nil,                           { pointer to name of executable module }
                            pCommandLine,                  { pointer to command line string }
                            nil,                           { pointer to process security attributes }
                            nil,                           { pointer to thread security attributes }
                            True,                          { handle inheritance flag }
                            CREATE_NEW_CONSOLE or
                            REALTIME_PRIORITY_CLASS,       { creation flags }
                            nil,                           { pointer to new environment block }
                            nil,                           { pointer to current directory name }
                            StartupInfo,                   { pointer to STARTUPINFO }
                            ProcessInfo);                  { pointer to PROCESS_INF }

    { wait for the app to finish its job and take the handles to free them later }

    if Result
    then
      begin

        WaitforSingleObject(ProcessInfo.hProcess, INFINITE);

        hAppProcess  := ProcessInfo.hProcess;
        hAppThread   := ProcessInfo.hThread;

      end
    else
      raise Exception.Create(ROUTINE_ID          + #10 +  #10 +
                             'Function failure'  + #10 +  #10 +
                             ErrMsg);

  FINALLY
    ShowMessage('posle finnally');
    { close the handles
      Kernel objects, like the process and the files we created in this case,
      are maintained by a usage count.
      So, for cleaning up purposes we have to close the handles
      to inform the system that we don't need the objects anymore }
    if hOutputFile <> 0 then CloseHandle(hOutputFile);
    if hInputFile <> 0 then CloseHandle(hInputFile);
    if hAppThread <> 0 then CloseHandle(hAppThread);
    if hAppProcess <> 0 then CloseHandle(hAppProcess);
    { restore the old cursor }
    Screen.Cursor:= OldCursor;
  END;
end;



provali sam da zakuca na redu

Code:
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);


ne mogu da provalim sta je to i zasto tu koci

izmena: provalio sam da ceka beskonacno dugo zbog INFINITE, ali sta ceka?
 
Odgovor na temu

savkic
Igor Savkić

Moderator
Član broj: 92186
Poruke: 2739



+92 Profil

icon Re: izlaz iz shellexecute u fajl24.08.2006. u 13:03 - pre 215 meseci
Ne moraš baš postovati čitave procedure. Te funkcije su deklarisane i implementirane u JclMiscel unitu JCL biblioteke, dovoljno je da skineš JCL sa www.delphi-jedi.org i da unit ubaciš u uses klauzulu. WaitForSingleObject sa INFINITE flagom čeka da handle procesa bude signaliziran tj. da se proces završi. Ako ti je potrebno da preuzimaš privremene rezultate iz procesa onda pogledaj WinExec32AndRedirectOutput i kako se koristi pipe objekat pa napravi nešto slično.
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: izlaz iz shellexecute u fajl

[ Pregleda: 2401 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.