If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > system command in C++ with arguments

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-05-04, 07:08
saikoushal saikoushal is offline
Registered User
 
Join Date: Nov 2003
Posts: 13
system command in C++ with arguments

hi
i am trying to run a shell script by calling it in a C++ program.
I am using system command to do so.
the shell script i am using needs two argument.
in the C++ the two arguments are return values from two functions
say arg1 arg2 (arg1 = 2000 , arg2 = 10)
i am using the system command as follows

system("sh ./shellscript arg1 arg2");

but the shell script is not taking the value of arg1(i.e. 2000) instead its taking "arg1" as argument and giving improper result.
Please guide me.
regards
sai koushal
Reply With Quote
  #2 (permalink)  
Old 04-05-04, 12:12
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
If you mean that arg1 and arg2 are two variables inside your C++ program, then you need to format them into the command string that you pass to the system function. Keep in mind that this is a very crude example, just to get you started thinking, but:
Code:
char buffer[200];
int arg1, arg2;
arg1 = 2000;
arg2 = 10;
sprintf(buffer, "sh ./shellscript %i %i", arg1, arg2);
system(buffer);
I think this will get you started, but if not feel free to post again.

-PatP
Reply With Quote
  #3 (permalink)  
Old 04-05-04, 21:54
saikoushal saikoushal is offline
Registered User
 
Join Date: Nov 2003
Posts: 13
Quote:
Originally posted by Pat Phelan
If you mean that arg1 and arg2 are two variables inside your C++ program, then you need to format them into the command string that you pass to the system function. Keep in mind that this is a very crude example, just to get you started thinking, but:
Code:
char buffer[200];
int arg1, arg2;
arg1 = 2000;
arg2 = 10;
sprintf(buffer, "sh ./shellscript %i %i", arg1, arg2);
system(buffer);
I think this will get you started, but if not feel free to post again.

-PatP
Thanks a lot....its working great
Reply With Quote
  #4 (permalink)  
Old 04-06-04, 01:07
saikoushal saikoushal is offline
Registered User
 
Join Date: Nov 2003
Posts: 13
Quote:
Originally posted by Pat Phelan
If you mean that arg1 and arg2 are two variables inside your C++ program, then you need to format them into the command string that you pass to the system function. Keep in mind that this is a very crude example, just to get you started thinking, but:
Code:
char buffer[200];
int arg1, arg2;
arg1 = 2000;
arg2 = 10;
sprintf(buffer, "sh ./shellscript %i %i", arg1, arg2);
system(buffer);
I think this will get you started, but if not feel free to post again.

-PatP
Thanks a lot....its working great
Reply With Quote
  #5 (permalink)  
Old 04-06-04, 03:55
saikoushal saikoushal is offline
Registered User
 
Join Date: Nov 2003
Posts: 13
Quote:
Originally posted by Pat Phelan
If you mean that arg1 and arg2 are two variables inside your C++ program, then you need to format them into the command string that you pass to the system function. Keep in mind that this is a very crude example, just to get you started thinking, but:
Code:
char buffer[200];
int arg1, arg2;
arg1 = 2000;
arg2 = 10;
sprintf(buffer, "sh ./shellscript %i %i", arg1, arg2);
system(buffer);
I think this will get you started, but if not feel free to post again.

-PatP
Thanks a lot....its working great
Reply With Quote
  #6 (permalink)  
Old 04-06-04, 07:35
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
It is great that that is working for you. Let us know if you have any problems with it.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On