473,472 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to call foreign programs from c?

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
Nov 14 '05 #1
3 3370
Niko Schwarz <ni**********@gmx.net> wrote:
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
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
Je***********@physik.fu-berlin.de writes:
Niko Schwarz <ni**********@gmx.net> wrote:
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.


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.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #3
Keith Thompson <ks***@mib.org> wrote:
Je***********@physik.fu-berlin.de writes:
Niko Schwarz <ni**********@gmx.net> wrote:
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.

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
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeremiah Jacks | last post by:
I just upgraded to MySQL 4.0.14-standard for RedHat Linux and am using = the pre-compiled binaries. I have a database with INNODB tables. When I insert a row into one of the child tables, I get...
2
by: geoff | last post by:
The table creation script(at the end of this post) works fine on 4.0.1-alpha-win, but the foreign key constraints fail on 4.0.15-win. I am starting the server with the same command for both...
31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
0
by: robert | last post by:
i use AQT mostly, and it uses ODBC and this call to show foreign key info. what it gets back is the PK of the referenced table, not the target column(s) of the foreign key. is this a shortcoming...
5
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
10
by: Shawn Chisholm | last post by:
Hi, I am trying to deal with a deadlock situation caused by foreign key references on insert and I was wondering if anyone knows what order the foreign keys are locked (or evaluated) in for a...
3
by: Steven | last post by:
Hello All, I am relatively new to database design and wanted to ask a few questions to see if I am on the right track regarding design and normalization. I am creating a user entity which is...
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.