Solved

System call in Delphi/Kylix

Posted on 2003-11-19
7
1,005 Views
Last Modified: 2010-05-18
Hi!
How to make a system call in Delphi/Kylix AND get the system responce into the application? (working under Windows and Linux)
0
Comment
Question by:Dragon222
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 9778601
hi, Dragon
what you mean with "system call" and "system response"?
0
 

Author Comment

by:Dragon222
ID: 9778802
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...)
0
 
LVL 6

Accepted Solution

by:
GloomyFriar earned 125 total points
ID: 9779331
You need to redirect child stdout and stderr streams.
0
 

Author Comment

by:Dragon222
ID: 9779370
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...
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9780453
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");
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question