473,841 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling external program in C++

is there a C++ method of calling an external executable program? I know you
can do it using C, but what about C++?

Jul 22 '05 #1
9 1975
Jon Slaughter wrote:
is there a C++ method of calling an external executable program? I know you
can do it using C, but what about C++?


Use the same way you know. C++ is often quite compatible with C in that
area. If you encounter a problem, come back and let's talk about it.

V
Jul 22 '05 #2
"Jon Slaughter" <no****@nowhere .com> ha scritto nel messaggio
news:10******** *****@corp.supe rnews.com...
is there a C++ method of calling an external executable program? I know you can do it using C, but what about C++?


I think that there is no standard way to do this...

So, in my opinion, the best way is to use the C -stylepossibly wrapped
inside a C++ method or something similar.

Andrea Sini

Jul 22 '05 #3
Jon Slaughter wrote:
is there a C++ method of calling an external executable program? I
know you can do it using C, but what about C++?


Same way, system().


Brian
Jul 22 '05 #4

"Lemon tree" <le***@tree.i t> wrote in message
news:M4******** **************@ news3.tin.it...
"Jon Slaughter" <no****@nowhere .com> ha scritto nel messaggio
news:10******** *****@corp.supe rnews.com...
is there a C++ method of calling an external executable program? I know you
can do it using C, but what about C++?


I think that there is no standard way to do this...


Yes there is. Standard function 'system()'. But note
that its argument and actual functionality are implementation-
specific (e.g. not all implementations have the necessary access
to a command processor.

So, in my opinion, the best way is to use the C -style

'system()' is as much a part of the C++ standard library as
it is of the C standard library.
possibly wrapped
inside a C++ method or something similar.


Why wrap it?

-Mike
Jul 22 '05 #5

Mike Wahler wrote:
"Lemon tree" <le***@tree.i t> wrote in message
news:M4******** **************@ news3.tin.it...
"Jon Slaughter" <no****@nowhere .com> ha scritto nel messaggio
I think that there is no standard way to do this...


Yes there is. Standard function 'system()'. But note
that its argument and actual functionality are implementation-
specific (e.g. not all implementations have the necessary access
to a command processor.

So, in my opinion, the best way is to use the C -style


'system()' is as much a part of the C++ standard library as
it is of the C standard library.
possibly wrapped
inside a C++ method or something similar.


Why wrap it?


Wrap it so you can add arguments more easily; the C interface
of system has a horrible way to add arguments (memory fiddling).
std::string has a decent operator+(). So even
void system( std::string const& );
is a useful wrapper.

Regards,
Michiel Salters

Jul 22 '05 #6

"msalters" <Mi************ *@logicacmg.com > wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .

Mike Wahler wrote:
"Lemon tree" <le***@tree.i t> wrote in message
news:M4******** **************@ news3.tin.it...
"Jon Slaughter" <no****@nowhere .com> ha scritto nel messaggio
I think that there is no standard way to do this...
Yes there is. Standard function 'system()'. But note
that its argument and actual functionality are implementation-
specific (e.g. not all implementations have the necessary access
to a command processor.

So, in my opinion, the best way is to use the C -style


'system()' is as much a part of the C++ standard library as
it is of the C standard library.
possibly wrapped
inside a C++ method or something similar.


Why wrap it?


Wrap it so you can add arguments more easily;


Huh? 'system()' takes exactly one argument.

the C interface
of system has a horrible way to add arguments (memory fiddling).
Huh? 'system()' takes exactly one argument, and it is provided
the same as for any other function. No 'fiddling' needed.
std::string has a decent operator+().
So you want to concatentate strings. You can do this easily for
C-style strings with 'strcat()'.
So even
void system( std::string const& );
is a useful wrapper.


It would let you pass a std::string object, yes. How useful
that might be is imo a matter of opinion. One can already
supply the contents of a std::string to 'system()' via
std::string::c_ str().

-MIke
Jul 22 '05 #7
> is there a C++ method of calling an external executable program?
I know you can do it using C, but what about C++?


Here's one possibility you might find interesting (this was a quick
hack at overhauling some code I wrote _years_ ago that used an
ostrstream, so it might benefit from some cleanup):

#include <sstream>
#include <cstdlib>

using std::ostringstr eam;

ostringstream &execute(ostrin gstream &s)
{
std::system(s.s tr().c_str());
return s;
}

ostringstream &operator<<(ost ringstream &s,
ostringstream &(*manip)(ostri ngstream &s))
{
return manip(s);
}

int main() {
ostringstream x;

x << "ls " << execute;

return 0;
}

If you want to see the original code, it's at:

http://groups-beta.google.com/group/...940ddf50edf667

I have to admit that until I looked at the date on that post, I hadn't
quite realized how old this really was. :-)

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #8
> is there a C++ method of calling an external executable program?
I know you can do it using C, but what about C++?


Here's a possibility you might find interesting:

#include <sstream>
#include <cstdlib>

using std::ostringstr eam;

ostringstream &execute(ostrin gstream &s) {
std::system(s.s tr().c_str());
return s;
}

ostringstream &operator<<(ost ringstream &s,
ostringstream &(*manip)(ostri ngstream &s))
{
return manip(s);
}

int main() {
ostringstream x;

x << "ls ";
x << execute;

return 0;
}

This is a quick hack of some much older code that used an strstream; it
might benefit from further work. In case you case, the original code is
here:

http://groups-beta.google.com/group/...940ddf50edf667

I must confess that I hadn't realized just HOW old this code was until
I looked at the date on that post...

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #9
Okay, I'll make _one_ more try at getting this posted -- as they say,
third time pays for all....
is there a C++ method of calling an external executable program?
I know you can do it using C, but what about C++?


Perhaps you'll find this an interesting possibility:

#include <sstream>
#include <cstdlib>

using std::ostringstr eam;

ostringstream &execute(ostrin gstream &s) {
std::system(s.s tr().c_str());
return s;
}

ostringstream &operator<<(ost ringstream &s,
ostringstream &(*manip)(ostri ngstream &s))
{
return manip(s);
}

int main() {
ostringstream x;

x << "ls ";
x << execute;

return 0;
}

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 22 '05 #10

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

Similar topics

1
8070
by: chandan | last post by:
Is it possible to call an external java program from a trigger in oracle 8i. I know that you can call a stored procedure in java from a trigger but i want to know is it possible to call an external java program
4
4978
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 to us by a vendor(PCMILER application). The C-Function does the following operations- Open the server,get distance between two points and close the server. It takes two input parameters(points). Whenever I call UDF via select statement it always...
11
1975
by: j23 | last post by:
I have library (static) testlib.cpp: #include <stdarg.h> void xxx(...) { char buf; va_list args; va_start(args, buf); va_end(args); }
11
543
by: RichN | last post by:
I am developing a c program in Visual Studio .NET 2003. I also have an Intel(R) Fortran compiler for MVS .NET My fortran sourcecode already existed. I started a new fortran project and chose to create a dynamic link library. The beginning of the fortran code looks like: SUBROUTINE SFTCK3 !DEC$ ATTRIBUTES DLLEXPORT::SFTCK3
1
1570
by: notregister | last post by:
How do i call out an external program(e.g. abc.exe) while hiding my current window form. when i exit this external program, how do i re-show my window form?
18
7533
by: utab | last post by:
Dear all, I am making a system call to the well known Gnuplot with system("gnuplot"); gnuplot opens if I only supply this command but I would like to pipe that command line in my C++ program. For example I want to run a very simple command like "plot sin(x)". So after running another program, what is the way to pipe that with some commands from inside the c++
2
5340
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
2
7156
by: Maydogg6 | last post by:
I need a hand with some stubborn link errors. I'm trying to recreate and old program from 6.0 into .NET, but for some reason when I try to compile I'm getting linking errors for all my function calls that deal with sockets. I've included <winsock2.h> in stdafx.h and I linked to ws2_32.lib by going to project properties->linker->general->additional library directories and typing in ws2_32.lib. Am I missing some include files or have the...
13
3396
by: Jeff | last post by:
We have an intranet website that currently uses ActiveX but we need to make it cross-browser compatible and also get around the problems we've been having with making it work with IE7 and Vista. We decided to write an external application to do the work from the client side. We are not sure how the web page can call the app though with parameters. For example, we want to do similar to what the MSDN Library and Audible are doing with...
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9706
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10667
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7851
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.