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

how to call system command with variable parameters?

I'm looking for a way to call system commands with variable parameters
within a Unix environment. Sort of like system() but i need to be
able to pass variable parameters....so I guess it would kind of look
like this:

system("command -%s -%s", parameter1, parameter2);

I've tried the above and it doesn't work when compiled with GCC.
Thanks.
Jul 22 '05 #1
4 9833
"shaggystyle" <sh*********@hotmail.com> wrote in message
news:6d**************************@posting.google.c om...
I'm looking for a way to call system commands with variable parameters
within a Unix environment. Sort of like system() but i need to be
able to pass variable parameters....so I guess it would kind of look
like this:

system("command -%s -%s", parameter1, parameter2);

I've tried the above and it doesn't work when compiled with GCC.
Thanks.


Hello

Use sprintf()

char temp[512];
sprintf(temp, "command -%s -%s", parameter1, parameter2);
system((char *)temp);

However this was not a C++ question.
--
Elias
Jul 22 '05 #2
On Wed, 18 Feb 2004 18:05:32 +0200 in comp.lang.c++, "lallous"
<la*****@lgwm.org> was alleged to have written:
Use sprintf()

char temp[512];
sprintf(temp, "command -%s -%s", parameter1, parameter2);
system((char *)temp);

However this was not a C++ question.


std::ostringstream cmd;
cmd << "command -" << parameter1 << " -" << parameter2;
system(cmd.str().c_str());

There, now it was a C++ question. :-)

Jul 22 '05 #3
In article <c1*************@ID-161723.news.uni-berlin.de>,
"lallous" <la*****@lgwm.org> wrote:
"shaggystyle" <sh*********@hotmail.com> wrote in message
news:6d**************************@posting.google.c om...
I'm looking for a way to call system commands with variable parameters
within a Unix environment. Sort of like system() but i need to be
able to pass variable parameters....so I guess it would kind of look
like this:

system("command -%s -%s", parameter1, parameter2);

I've tried the above and it doesn't work when compiled with GCC.
Thanks.
Hello

Use sprintf()

char temp[512];


What if the command plus it's parameters is longer than 511 characters?
Use ostringstream instead.
sprintf(temp, "command -%s -%s", parameter1, parameter2);
system((char *)temp);

This cast is completely redundant.

Jul 22 '05 #4
David Harmon <so****@netcom.com> wrote in message news:<40****************@news.west.earthlink.net>. ..
On Wed, 18 Feb 2004 18:05:32 +0200 in comp.lang.c++, "lallous"
<la*****@lgwm.org> was alleged to have written:
Use sprintf()

char temp[512];
sprintf(temp, "command -%s -%s", parameter1, parameter2);
system((char *)temp);

However this was not a C++ question.


std::ostringstream cmd;
cmd << "command -" << parameter1 << " -" << parameter2;
system(cmd.str().c_str());

There, now it was a C++ question. :-)


Thanks for the tip!

--
Elias
Jul 22 '05 #5

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

Similar topics

5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
1
by: Brian Conway | last post by:
Hope someone can help. I am trying to get a submit button working and getting this error now System.InvalidCastException: Object must implement IConvertible. This is showing up on the...
6
by: JLK | last post by:
I'm having a bit of a time with the following code. I can script this real easy in Bash but I'm trying to practice my C++: ******************************************************* #include...
3
by: Chris | last post by:
Hello everyone I want to call a DB2 7.2 stored procedure via ADO in VC++ 7.1 It has 4 parameters, the 1st and the 4th are OUTPUT and the others are INPUT params. My code looks like this:...
2
by: Steven K | last post by:
Hello, With ASP, I could indicate that a variable was a stored procedure with parameters by using "adcmdStoredProc", and set the data variable with one line using the Execute command (cnnSearch...
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
9
by: C++ Newbie | last post by:
Hi, Why doesn't the following C++ program echo the value of 97? If you manually "head -3 temp.txt | tail -1" the temp.txt file, you will get 97. Use it in a system call, and it doesn't work. ...
0
ashitpro
by: ashitpro | last post by:
Writing System Call Wrappers in User Space. Recently I saw a post in Linux/Unix section to know the user who deleted the file in linux. Currently there is nothing in linux which could achieve...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.