System call in Delphi/Kylix

How to make a system call in Delphi/Kylix AND get the system responce into the application? (working under Windows and Linux)
Who is Participating?
GloomyFriarConnect With a Mentor Commented:
You need to redirect child stdout and stderr streams.
hi, Dragon
what you mean with "system call" and "system response"?
Dragon222Author Commented:

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...)
Dragon222Author Commented:
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,
    if( !fSuccess )
        ErrorExit("DuplicateHandle failed");

// 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");
All Courses

From novice to tech pro — start learning today.