LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 09-11-2003, 07:47 AM   #1
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Rep: Reputation: 30
How to call other program?


This is the source code in <<Thinking in C++>> volume one, chapter 2, Making and using object.
Code:
//: C02:CallHello.cpp
// Call another program
#include <cstdlib> // Declare "system()"
using namespace std;

int main() {
  system("Hello");
} ///:~
I can successfully compile Hello.cpp and run it, but I don't know how to compile CallHello.cpp and run it successfully.

Thank you.
 
Old 09-11-2003, 08:09 AM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
how about:

g++ -o CallHello CallHello.cpp
./CallHello

i assume if you compiled Hello.cpp then you did this already which means you getting some sort of error, if you tell us what it is we might be able to help
 
Old 09-11-2003, 08:53 AM   #3
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Original Poster
Rep: Reputation: 30
Thank you.
[root@localhost first]# g++ CallHello.cpp -o CallHello
(No error when compile.)
[root@localhost first]# ./CallHello
sh: line 1: Hello: command not found
(Such error occur when the program is run.)
 
Old 09-11-2003, 09:07 AM   #4
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Then you are missing the "Hello" program that you are trying to call.
 
Old 09-11-2003, 09:12 AM   #5
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
Quote:
Originally posted by Strike
Then you are missing the "Hello" program that you are trying to call.
possibly but he says he's compiled that and its ok.

Xiangbuilder: try system("./Hello"); in CallHello.cpp and see what happens. also do you really need root privilages to do this??
 
Old 09-11-2003, 10:31 AM   #6
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Original Poster
Rep: Reputation: 30
I tried system("./Hello"); in CallHello.cpp and it is ok, then.
I wonder if you leave system("Hello") instead of system("./Hello") in CallHello.cpp, and and you can successfully compile Hello.cpp and run it,
can you successfully compile CallHello.cpp and run it in your machine?
I ask the question because the words in the book is system("Hello") rather than system("./Hello").
I offten see some command such as "xxx" in web, in fact, to run it, we must type ./xxx instead of xxx.
Thank you.
 
Old 09-11-2003, 10:47 AM   #7
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 31
<<Thinking in C++>> is not O.S specific.
But "./XXX" to excecute the file is the linux rule.

I think...
 
Old 09-11-2003, 11:14 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally posted by captainstorm
<<Thinking in C++>> is not O.S specific.
But "./XXX" to excecute the file is the linux rule.

I think...
That's only if . (the current directory) isn't in your path variable. If it is, you can simply type the name of the executable, eg CallHello.
 
Old 09-11-2003, 12:02 PM   #9
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
As previously noted, linux uses ./ to specify an executable in the current directory. I have no idea what OS the author of Thinking in C++ was using when writing the book, but it could have been windows or one of the versions of Unix that does not require ./
I have no idea what versions of Unix those would be, but Ive heard they exist.
 
Old 09-11-2003, 12:09 PM   #10
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
by jinksys
I have no idea what OS the author of Thinking in C++ was using when writing the book, but it could have been windows

the author, Bruce Eckel was writing in windows as volume two of his book comes in MSWord format or at least it did when i read it.

by jinksys
I have no idea what versions of Unix those would be, but Ive heard they exist.

any version of unix where someone cares to type
Code:
export PATH=$PATH:.
assuming bash, i dont know my other shells very well.
 
Old 09-11-2003, 12:41 PM   #11
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
Thanks for clearing that up.
 
Old 09-11-2003, 09:13 PM   #12
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Original Poster
Rep: Reputation: 30
Thank you.
 
  


Reply



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
how to call C function in FORTRAN program bigapple Programming 5 08-24-2005 12:30 AM
call a c program in a shell script jagman Programming 4 04-05-2005 04:58 PM
Capturing program feedback... (not sure what to call it) CrazyPilot Programming 3 03-20-2005 11:10 AM
call other program at run time Xiangbuilder Programming 4 10-01-2003 09:53 AM
Call Other Application by one Program kiennd Programming 4 08-02-2003 01:52 AM

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

All times are GMT -5. The time now is 11:25 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
Open Source Consulting | Domain Registration