LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2004, 11:05 PM   #1
becky_starr
Member
 
Registered: Jan 2004
Posts: 34

Rep: Reputation: 15
run another program in a program


I would like to ask how I can run another program in a progaram already running.


That is a program is used to check something and when something occurs,
this program will stop and another program will start~~~


Thanks again~~
 
Old 02-14-2004, 11:47 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
What language?

In C and C++, you can use the 'exec' family of functions (check out the 'exec' man page); in bash and other scripting languages you can usually just enclose a command in "`" (reverse single quotes) to execute it.
 
Old 02-15-2004, 07:10 AM   #3
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Rep: Reputation: 38
In C/C++ I use

system("run your script here or just execute directly"); // like commandline

the system call takes care of fork, exec etc
 
Old 02-15-2004, 09:31 AM   #4
becky_starr
Member
 
Registered: Jan 2004
Posts: 34

Original Poster
Rep: Reputation: 15
so what header file I have to include.

system("./test.o");


where test.o is the file to be run, is the command correct?
 
Old 02-15-2004, 10:10 AM   #5
becky_starr
Member
 
Registered: Jan 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks kalleanka and wapcaplet

I have checked that the command
system("./test.o");
works well when I want to upgrade the file but not make a connection to other pc.

besides I have tried using execl to update file too ..but can't make connection..

Are there any special technique in using them?

From the man page, it doesn't mention any sample code, it is really hard for me to get the correct thing I want.

Could anyone guide me (or show me the exact code)

thanks again and agian~~
 
Old 02-15-2004, 11:08 AM   #6
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I'm not sure what you mean by "upgrading the file" or making a connection to another PC. Could you explain a little more?
 
Old 02-15-2004, 11:44 AM   #7
becky_starr
Member
 
Registered: Jan 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Suppose there are 3 PCs. message sent from pc 1 to pc 3 through pc 2,

pc 1 is running a server.o program to wait for connection from another pc.

when packet sent from pc 1 to pc 3 through pc 2, pc 2 will use a iptables command (-j QUEUE)to pass the packet to the queue and then a userspace program which starts running at the beginning will try to make connection to pc 1.
( I have add the command execl("client.o","",(char *) 0); at the userspace program at pc 2, but it fails to make connection to pc 1.)
(But it works if I just add the command execl("add.o","",(char *) 0); )

add.o is just a program for adding iptables command
client.o is a program for making connection to pc 1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I want to ask if I can get the message sent from pc 1 to pc 3 at pc 2 even the connection is made only between pc 1 and pc 3.

Actually, I want to do this .....

I have no idea at all~~~

So, I try to pass the packet to the queue at pc 2, run a userspace program--make connection to pc 1 and ask pc 1 to send the message to pc 2~~~
 
Old 02-15-2004, 11:46 AM   #8
becky_starr
Member
 
Registered: Jan 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks wapcaplet ~~

Could you show me the function or anything useful to solve my problem....

I have tried many many .....methods before

Thanks a lot~~~
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to run mfo6463 Linux - Newbie 2 04-21-2004 07:28 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM
please help me run this program joe blow Linux - Newbie 4 08-08-2003 10:07 AM
How do I run a program? rtstar Linux - Newbie 2 07-25-2003 09:08 AM
Want to run a program from a program GoboFraggle Programming 3 04-21-2003 08:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration