473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

calling external program from within C++

Hi,
I have a shell script which takes three arguments, how can I call this
script from within a C++ program.
I am new to C++ programming and not sure how to accomplish this.
I tried using system() call but could make it work, must be doing
something wrong.
Appreciate any help in this regard.

Thanks,
Juggler

Nov 14 '05 #1
5 1870
Did you try system("bash nameofscript arg1 arg2")?
(I think that is the syntax.)

Nov 14 '05 #2
Juggler wrote:
I have a shell script which takes three arguments, how can I call
this script from within a C++ program.


Please don't ask C++ questions in comp.lang.c.

Try comp.lang.c++.

--
Peter

Nov 14 '05 #3
"Peter Nilsson" <ai***@acay.com.au> writes:
Juggler wrote:
I have a shell script which takes three arguments, how can I call
this script from within a C++ program.


Please don't ask C++ questions in comp.lang.c.

Try comp.lang.c++.


But the answer happens to be the same in C and C++: use the system()
function.

The OP says he tried this and it didn't work. Without knowing exactly
what he tried or how it "didn't work", we can't guess what the problem
might be.

--
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 #4
Keith Thompson wrote:
"Peter Nilsson" <ai***@acay.com.au> writes:
Juggler wrote:
I have a shell script which takes three arguments, how can
I call this script from within a C++ program.
^^^^^^^^^^^^^^^^^^^^^^^^^
Please don't ask C++ questions in comp.lang.c.

Try comp.lang.c++.
But the answer happens to be the same in C and C++: use the
system() function.


No. The function may be the same, but the _application_ of it isn't.
The OP says he tried this and it didn't work. Without knowing
exactly what he tried or how it "didn't work", we can't guess
what the problem might be.


We don't _need_ to. The OP explicitly wants a _C++_ solution. Where
should the OP go for that? comp.lang.c?!

But think about it, Keith...

Since <stdlib.h> is deprecated in C++, then giving them a _C_
solution is the _wrong_ answer, even if it happens to be
correct in clc.

Even if that isn't the case, do you think clc should start
accepting code with #include <iostream>, etc... etc... in
cases where there's a chance that there is a C solution?

Personally, I think not, hence my reply.

--
Peter

Nov 14 '05 #5
In article <11**********************@l41g2000cwc.googlegroups .com>,
Peter Nilsson wrote:
Keith Thompson wrote:
"Peter Nilsson" <ai***@acay.com.au> writes:
> Juggler wrote:
> > I have a shell script which takes three arguments, how can
> > I call this script from within a C++ program.
[...] But the answer happens to be the same in C and C++: use the
system() function.
[...] But think about it, Keith...

Since <stdlib.h> is deprecated in C++, then giving them a _C_
solution is the _wrong_ answer, even if it happens to be
correct in clc.


The fact that stdlib.h is deprecated in C++ is only of academic
interest, if at all. The C++ standardization committee still actively
tries to keep the language as compatible with C as possible (``... but
no more!''), so removal of the C headers would be about the most
nonsensical step they could take, since it would instantly break source
compatibility with virtually every (complete) piece of C code for
absolutely no good reason. Don't expect it to happen within the next
decade.

And even if they will be removed some time in a very distant future,
then you can wait for an even longer time, or indeed forever, for the
implementors to drop support as well (and as I'll explain below, many if
not most typical implementations of the standard C++ library *still* do
not even get the C++ replacements for the C headers right.)

There are other valid reasons against using the C headers, but the
deprecation one is certainly not one that weighs much at all, and you
can ignore it if you feel that your C++ code should be using them (e.g.
because you may wish to compile the code with both C and C++ compilers,
whether that is a good thing to wish or not aside.)

A *good* reason is that the C++ versions ought to keep the namespace
clean by placing most of what is in the C headers into the standard
namespace and making it available only upon explicit request. But
unfortunately, even this one usually does not hold in practice, because
many C++ libraries implement the C++ versions atop of the C headers, and
they do *not* keep the namespace clean as they should.

SuSE Linux with libstdc++-devel-3.3-23:

/home/nils [0]> cat new.cpp
#include <cstdio>

typedef int FILE;

int
main(void) {
}
/home/nils [0]> c++ new.cpp -o new
new.cpp:3: error: conflicting types for `typedef int FILE'
/usr/include/stdio.h:46: error: previous declaration as `typedef struct
_IO_FILE FILE'
HP-UX 11i with HP's aC++ A.03.50:

nils@Ariel:~> aCC new.cpp -o new -AA
Error 173: "new.cpp", line 3 # Redefinied symbol 'FILE': previously
defined at ["/usr/include/stdio.h", line 45]
typedef int FILE;
^^^^

(Note that the above code is actually illegal because the C++ standard
says that:

For each type T from the Standard C library, the types ::T and
std::T are reserved to the implementation and, when defined, ::T
shall be identical to std::T.

However, I used this example only for the illustrative error messages.
You can e.g. call printf() without explicitly prepending it with std::
or using an equivalent ``using'' directive to test the implementation,
as well.)

--
My real email address is ``nils<at>gnulinux<dot>nl''
Nov 14 '05 #6

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

Similar topics

3
by: Glenn C. Rhoads | last post by:
I'm having a problem calling a C function from a publicly available library file. To get the code to compile, I had to declare the function as an external C function as follows. extern "C"...
2
by: Juggler | last post by:
Hi, I have a shell script which takes three arguments, how can I call this script from within a C++ program. I am new to C++ programming and not sure how to accomplish this. I tried using...
4
by: Sivakumar Shanmugam | last post by:
Group.. We are running on db2 UDF V8 on Sun solaris platform. I created an UDF which calles a C-routine(SQL_API_FN). This C-routine in turn calls an external C-function. The C-function is provided...
1
by: Aged | last post by:
Hi I have asked several groups now for advise but I feel I must be confusing either them or myself, but anyway here goes! Below is code taken from the "OnClick" function of a command button...
1
by: Laszlo | last post by:
Hi all, As a novice I installed PostgreSQL 7.2.1 on Win32 and works, Borland C++Builder Enterprise Suite 5.0 (build 12.34) what works too. I decided to combine these two programs and develop a...
4
by: gregarican | last post by:
What's the easiest and cleanest way of having PyQt bring up an external application? In this case I am looking to launch Internet Explorer and bring up a specific URL. I don't care about tracking...
0
by: Michael | last post by:
Trying to call an external DLL (compiled within Fortran) and keep on getting the following error in the main call to the external DLL ' Object reference not set to instance of object' The DLL...
0
by: Chico Jayanthan | last post by:
Hi, I call an external windows program (.exe) from a python script. Something like os.system('test.exe'). I want to set a timeout for the external windows program to return. If no results are...
11
by: Emmanouil Angelakis | last post by:
Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.