Student question on external calls.

H

Hagar

I am currently learning C++ and am into a project for the end of the
semester finals. Everything is rosy except for one feature that I want
to include and can't find in my very large and expensive C++ books. Plus,
I don't want to ask the instructor because that will give my project away.

How do you call an external non C++ program, or possibly a system
function? For instance, I have some very good Perl modules from my last
class that parse text files and I would like to call them from a menu in
my C program. (Why the heck, you say? Because in theory, my program can
call external scripts that can be changed by the assumed user and if they
were compiled into MAIN then they would be fixed functions. Remember,
this is for credit, not deployment.)

But I don't find anything (or maybe don't recognize it) in
my manuals - calling, external calls, external functions, system, system
calls, etc - apparently none of the above. I even spent some time in the
local Booksamillion looking through their stacks (for free, I admit it)
and didn't find the keyword I am looking for.

What is interesting is that I can easily call a C program from a Perl
script, but not the other way around.

Anybody?

Thanks all
Hagar (but not too horrible).
 
R

Rakesh Kumar

Therez a C function by name - 'system (<path_to_exec> ) ' that can do
what you want ! Check it out in google.
 
J

Jeff Schwab

Hagar said:
How do you call an external non C++ program, or possibly a system
function? For instance, I have some very good Perl modules
....

What is interesting is that I can easily call a C program from a Perl
script, but not the other way around.

To pass arbitrary commands to your execution environment, use the
"system" function from <cstdlib>. Perl also has excellent facilities
for being embedded in C and C++ programs.

http://search.cpan.org/~abergman/ponie-2/perl/pod/perlembed.pod

3rd-party libraries are available to make it even easier. E.g., see:

http://search.cpan.org/~jtobey/pickle-0.5.1/pickle.pod
 
H

Hagar

But I don't find anything (or maybe don't recognize it) in
my manuals - calling, external calls, external functions, system, system


Thanks guys. Interestingly, system is what perl uses to call outside the
main code. But... There is not a single reference to the system command
in either of my C++ books, or popen or exec which others have suggested -
apparently, students aren't supposed to move outside of the box.

Obviously, what I need is a genuwine C++ book from a non-college
bookstore. However, even though those don't cost as much as the ripoff
price of textbooks, they still are not cheap, studentwise. Maybe I can
code some rich kids homework for the price:)

Thanks
Hagar (but not too horrible).
 
R

red floyd

Hagar said:
Thanks guys. Interestingly, system is what perl uses to call outside the
main code. But... There is not a single reference to the system command
in either of my C++ books, or popen or exec which others have suggested -
apparently, students aren't supposed to move outside of the box.

Obviously, what I need is a genuwine C++ book from a non-college
bookstore. However, even though those don't cost as much as the ripoff
price of textbooks, they still are not cheap, studentwise. Maybe I can
code some rich kids homework for the price:)

No. popen() and exec() won't be in any book describing C++, as they
aren't part of the Standard. They would be in a book describing "C++
Programming in a [YOUR_OS_HERE] Environment".

I don't recall whether system() is part of the Standard either, but it
would be described in the second type of book ("C++ for XXX Environment").
 
D

Default User

Hagar said:
Thanks guys. Interestingly, system is what perl uses to call outside the
main code. But... There is not a single reference to the system command
in either of my C++ books,

That's a failing.
or popen or exec which others have suggested -

There are no such things in C++. Some implementations have extensions by
these names, but unless your book specificially covers that platform, it
would not be unusual for it not to mention them. You don't mention which
books you are using.
apparently, students aren't supposed to move outside of the box.

I don't understand this statement.
Obviously, what I need is a genuwine C++ book from a non-college
bookstore. However, even though those don't cost as much as the ripoff
price of textbooks, they still are not cheap, studentwise. Maybe I can
code some rich kids homework for the price:)

Check your local public library, it may have useful books.


Brian Rodenborn
 
D

Default User

red said:
I don't recall whether system() is part of the Standard either, but it
would be described in the second type of book ("C++ for XXX Environment").

Yes, it is.



Brian Rodenborn
 
H

Hagar

That's a failing.


As my instructor says, textbooks are to make publishers money - they have
nothing to do with teaching or learning - unfortunately, they are also
mandated by the state based on the amount of donations received by
politicians from publishers.


n't supposed to move outside of the box.
I don't understand this statement.
Just some minor sarcasm.

Check your local public library, it may have useful books.

Brian - You are not from East Texas, are you? In our only public library
there are books about the latest advances in V2 rocketry, history books
that speculate on what the world will be like after WWII ends, the latest
research on vacuum tube radios, and info on something called a wire
recorder that actually records voices.

Oh yes. There is also a programming book. It is about Autocoder
that runs on an IBM 1401 ??? (whatever the heck that is).


I think I better wait till I have the money to visit a real Dallas book
store.

Hagar
 
D

Default User

Hagar said:
Brian - You are not from East Texas, are you?
No.

Oh yes. There is also a programming book. It is about Autocoder
that runs on an IBM 1401 ??? (whatever the heck that is).

Almost any library can get books via inter-library loan.




Brian Rodenborn
 

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
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top