473,216 Members | 1,363 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,216 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 9825
"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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.