473,320 Members | 2,080 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,320 software developers and data experts.

PN: Sample code to call another program/command from inside a C++ program

Hi All,
I have written some software that performs ETL processing to load data
warehouses. Each program accepts a set of parameters and returns 0 or
1 to the win/unix shell to indicate success or failure. Currently it
is run as a set of commands that calls each program and then returns
the return code and stops if the program has failed.

I'm interested in enhancing the product by being able to call these
programs from within another C++ program. This way I could create a
table of programs to run and parameters to use and then the calling
program could simply read the table, call each program in turn, and
stop if there was an error. I could then add a GUI to set up the table
of programs to run with parameters to pass.

The entry point to each program is the normal main argv argc and the
parameters are just a character string....the current version runs on
win2k/unix.

If anyone has a snippet of sample code to show me how to do this I
would very much appreciate it.

Best Regards
Peter Nolan.
Jul 22 '05 #1
8 2553
Peter Nolan wrote:
Hi All,
I have written some software that performs ETL processing to load data
warehouses. Each program accepts a set of parameters and returns 0 or
1 to the win/unix shell to indicate success or failure. Currently it
is run as a set of commands that calls each program and then returns
the return code and stops if the program has failed.

I'm interested in enhancing the product by being able to call these
programs from within another C++ program. This way I could create a
table of programs to run and parameters to use and then the calling
program could simply read the table, call each program in turn, and
stop if there was an error. I could then add a GUI to set up the table
of programs to run with parameters to pass.

The entry point to each program is the normal main argv argc and the
parameters are just a character string....the current version runs on
win2k/unix.

If anyone has a snippet of sample code to show me how to do this I
would very much appreciate it.

Best Regards
Peter Nolan.


Try the std::system function.

- Pete
Jul 22 '05 #2
Peter Nolan wrote:
Hi All,
I have written some software that performs ETL processing to load data
warehouses. Each program accepts a set of parameters and returns 0 or
1 to the win/unix shell to indicate success or failure. Currently it
is run as a set of commands that calls each program and then returns
the return code and stops if the program has failed.

I'm interested in enhancing the product by being able to call these
programs from within another C++ program. This way I could create a
table of programs to run and parameters to use and then the calling
program could simply read the table, call each program in turn, and
stop if there was an error. I could then add a GUI to set up the table
of programs to run with parameters to pass.

The entry point to each program is the normal main argv argc and the
parameters are just a character string....the current version runs on
win2k/unix.

If anyone has a snippet of sample code to show me how to do this I
would very much appreciate it.

Best Regards
Peter Nolan.


Try the std::system function.

- Pete
Jul 22 '05 #3
"Pete" <x@x.x> wrote in message news:<B9******************@newsread2.news.pas.eart hlink.net>...
Best Regards
Peter Nolan.


Try the std::system function.

- Pete


Hi Pete,
thanks for the pointer.....I wrote a short C++ program as follows.

However, it looks to me that system will wait for the call to return
before moving on to the next statement.

What I am looking for is how I might go about starting several
programs at once and running them concurrently. For example, I might
have 100 files to load from various places to a staging area and then
move that data forward to the DW. Today running a reasonable number of
jobs and dependencies are managed in scripts....but I'd like to be
able to manage running jobs at once and then detect that they have all
completed ok before moving onto the next part of the batch....I've
been reading up about spawn and things like that in VS.net but I don't
seem to find the command that will let me start a command and then
come back to see how it is going...I know it exists because I read
about it in one of my reference books that is currently 5,000 miles
away from me....but I can't remember what it was and can't find it in
the vs.net library....

Any tips most apperciated.. :-)
#include <process.h>

int main(int argc, char* argv[])
{

int return_code ;

return_code = 0 ;

return_code = system( "type c:\\temp.txt2" );

return (return_code) ;
}
Jul 22 '05 #4
"Pete" <x@x.x> wrote in message news:<B9******************@newsread2.news.pas.eart hlink.net>...
Best Regards
Peter Nolan.


Try the std::system function.

- Pete


Hi Pete,
thanks for the pointer.....I wrote a short C++ program as follows.

However, it looks to me that system will wait for the call to return
before moving on to the next statement.

What I am looking for is how I might go about starting several
programs at once and running them concurrently. For example, I might
have 100 files to load from various places to a staging area and then
move that data forward to the DW. Today running a reasonable number of
jobs and dependencies are managed in scripts....but I'd like to be
able to manage running jobs at once and then detect that they have all
completed ok before moving onto the next part of the batch....I've
been reading up about spawn and things like that in VS.net but I don't
seem to find the command that will let me start a command and then
come back to see how it is going...I know it exists because I read
about it in one of my reference books that is currently 5,000 miles
away from me....but I can't remember what it was and can't find it in
the vs.net library....

Any tips most apperciated.. :-)
#include <process.h>

int main(int argc, char* argv[])
{

int return_code ;

return_code = 0 ;

return_code = system( "type c:\\temp.txt2" );

return (return_code) ;
}
Jul 22 '05 #5
Peter Nolan wrote:
"Pete" <x@x.x> wrote in message news:<B9******************@newsread2.news.pas.eart hlink.net>...
Best Regards
Peter Nolan.


Try the std::system function.

- Pete

Hi Pete,
thanks for the pointer.....I wrote a short C++ program as follows.

However, it looks to me that system will wait for the call to return
before moving on to the next statement.

What I am looking for is how I might go about starting several
programs at once and running them concurrently.


Basically there's no good way to do what you want using standard C++.
Frankly, most uses of system() would be better replaced with
system-specific functions that offer more control.

The best suggestion I can offer is to look at what is provided by your
execution environment, and direct your questions to a group that
discusses programming for your particular system.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #6
Peter Nolan wrote:
"Pete" <x@x.x> wrote in message news:<B9******************@newsread2.news.pas.eart hlink.net>...
Best Regards
Peter Nolan.


Try the std::system function.

- Pete

Hi Pete,
thanks for the pointer.....I wrote a short C++ program as follows.

However, it looks to me that system will wait for the call to return
before moving on to the next statement.

What I am looking for is how I might go about starting several
programs at once and running them concurrently.


Basically there's no good way to do what you want using standard C++.
Frankly, most uses of system() would be better replaced with
system-specific functions that offer more control.

The best suggestion I can offer is to look at what is provided by your
execution environment, and direct your questions to a group that
discusses programming for your particular system.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #7
Kevin Goodsell wrote:
Peter Nolan wrote:
Pete wrote:
Try the std::system function.
thanks for the pointer.....I wrote a short C++ program as follows.

However, it looks to me that system will wait for the call to return
before moving on to the next statement.

What I am looking for is how I might go about starting several
programs at once and running them concurrently.


Basically there's no good way to do what you want using standard C++.
Frankly, most uses of system() would be better replaced with
system-specific functions that offer more control.

The best suggestion I can offer is to look at what is provided by your
execution environment, and direct your questions to a group that
discusses programming for your particular system.

cat main.cc

#include <iostream>

int main(int argc, char* argv[]) {
std::system("xclock &");
return 0;
}

works fine for me.

Jul 22 '05 #8
Kevin Goodsell wrote:
Peter Nolan wrote:
Pete wrote:
Try the std::system function.
thanks for the pointer.....I wrote a short C++ program as follows.

However, it looks to me that system will wait for the call to return
before moving on to the next statement.

What I am looking for is how I might go about starting several
programs at once and running them concurrently.


Basically there's no good way to do what you want using standard C++.
Frankly, most uses of system() would be better replaced with
system-specific functions that offer more control.

The best suggestion I can offer is to look at what is provided by your
execution environment, and direct your questions to a group that
discusses programming for your particular system.

cat main.cc

#include <iostream>

int main(int argc, char* argv[]) {
std::system("xclock &");
return 0;
}

works fine for me.

Jul 22 '05 #9

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

Similar topics

0
by: Peter Nolan | last post by:
Hi All, I have written some software that performs ETL processing to load data warehouses. Each program accepts a set of parameters and returns 0 or 1 to the win/unix shell to indicate success or...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
14
by: nullptr | last post by:
Hi, As an exercise, I've written a program implementing run-length encoding. I would be more that happy to hear your comments, suggestions, etc Thanks, --- #include <stdio.h> #include...
19
by: Dave | last post by:
I'm building a research application that needs to be a super speed demon. I decided that one way to do this is to use goto loops instead of while() loops when I need them. that way, instead of...
15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
13
by: Larry Menard | last post by:
Test code: $dbconn = odbc_connect($dbname, $username, $password); $path = "C:\Temp\myJar.jar"; $statement = "CALL SQLJ.INSTALL_JAR('file://$path', 'myJarId')"; $result = odbc_exec($dbconn,...
52
by: Julie | last post by:
I'm supporting an application at work. Below are some code segments that I can't understand how they work. First let me say, I would never code this standard. I'm just really creeped out that it...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.