Link to home
Start Free TrialLog in
Avatar of Dragon222
Dragon222

asked on

System call in Delphi/Kylix

Hi!
How to make a system call in Delphi/Kylix AND get the system responce into the application? (working under Windows and Linux)
Avatar of mocarts
mocarts

hi, Dragon
what you mean with "system call" and "system response"?
Avatar of Dragon222

ASKER

Well...

If I run System('ls') in my Kylix application, how do I then get te output from ls back into my application (like into some Memo component)?

(Ok I can do like this, System('ls > myfile') and then read from this temporary file, but this is ugly...)
ASKER CERTIFIED SOLUTION
Avatar of GloomyFriar
GloomyFriar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tanks, GloomyFriar!

But please, for a novice like me, can you write down the few lines of code that I need... without some example I'm as lost as before...
I have no the sample code in Delphi. If it helps below is code in C (for Windows)

   // The steps for redirecting child process's STDOUT:
   //     1. Save current STDOUT, to be restored later.
   //     2. Create anonymous pipe to be STDOUT for child process.
   //     3. Set STDOUT of the parent process to be write handle to
   //        the pipe, so it is inherited by the child process.
   //     4. Create a noninheritable duplicate of the read handle and
   //        close the inheritable read handle.
 
// Save the handle to the current STDOUT.
 
   hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
 
// Create a pipe for the child process's STDOUT.
 
   if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
      ErrorExit("Stdout pipe creation failed\n");
 
// Set a write handle to the pipe to be STDOUT.
 
   if (! SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr))
      ErrorExit("Redirecting STDOUT failed");
 
// Create noninheritable read handle and close the inheritable read
// handle.

    fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
        GetCurrentProcess(), &hChildStdoutRdDup , 0,
        FALSE,
        DUPLICATE_SAME_ACCESS);
    if( !fSuccess )
        ErrorExit("DuplicateHandle failed");
    CloseHandle(hChildStdoutRd);

// Now create the child process.
 
   if (! CreateChildProcess((LPCTSTR)run)) /* Just a wrapper to CreateProcess */
      ErrorExit("Create process failed");
 
// After process creation, restore the saved STDIN and STDOUT.
 
   if (! SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout))
      ErrorExit("Re-redirecting Stdout failed\n");