how to call foreign programs from c?

N

Niko Schwarz

Hello,

I'd like to run check from within my c program a gnupg signature. The
easiest way should be to simply call gnupg, right? But how do i get
the output of that program into a string?

best regards,

niko
 
J

Jens.Toerring

Niko Schwarz said:
I'd like to run check from within my c program a gnupg signature. The
easiest way should be to simply call gnupg, right? But how do i get
the output of that program into a string?

Unless you are prepared to resort to non-standard, platform-specific
solutions the only way you can do that is using the system() function
and have the external program write to a file. That file you read in
from the C program to get the output into your string.

<OT>
If you don't mind using a platform-specific solution and you're using
UNIX it might be worthwhile to have a look at the popen() function. I
guess that it's also available on Windows.
</OT>
Regards, Jens
 
K

Keith Thompson

Unless you are prepared to resort to non-standard, platform-specific
solutions the only way you can do that is using the system() function
and have the external program write to a file. That file you read in
from the C program to get the output into your string.

But there's no portable way to tell an external program to write its
output to a file. Many systems will support

system("gpg blah blah > output.txt");

but most such systems probably also support the (non-standard) popen()
function. As long as you're writing non-portable code anyway, you
might as well do it in a way that avoids creating a superfluous
temporary file.

If you want to be fanatical about portability, you can have some
external source (the user or a config file) specify the command string
to be passed to system(), but I wouldn't bother.

(If you have questions about popen() that aren't answered by your
system's documentation, comp.unix.programmer is the place to ask
them.)
 
J

Jens.Toerring

But there's no portable way to tell an external program to write its
output to a file. Many systems will support
system("gpg blah blah > output.txt");

I was assuming that either that is possible or that the external
program has some options to tell it to write its output to a file.
If neither of these assumptions is true the OP draws a blank;-)

Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top