![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to get number char from a string | netbanker | Shell Programming and Scripting | 4 | 07-16-2008 04:16 PM |
| last char from a string | broli | Shell Programming and Scripting | 6 | 12-07-2007 08:02 PM |
| replacing char with string | phani_sree | High Level Programming | 1 | 11-20-2006 08:57 AM |
| string of 7 char length always... | thanuman | UNIX for Dummies Questions & Answers | 3 | 04-12-2005 01:51 PM |
| Compare Char to String | Phobos | High Level Programming | 3 | 04-09-2005 12:01 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
pass char string via system()
hello all
i am trying to pass a argument through system function to a shell script. Code:
#shell script echo.sh to display the string echo $1 Code:
#include<stdlib.h>
int
main()
{
const char *str = "hello all";
system("sh echo.sh str");
}
|
|
||||
|
The system command expects a string with a command and str within the command is passed as a literal string, not as a variable. Assign the command to a string before you pass it to the system function, something like:
Code:
#include <stdlib.h>
int main()
{
const char *str = "echo hello all";
system(str);
}
|
|
||||
|
thank you for your reply,
actually "hello all" is not fixed, it can be any string coming from a java program which i further pass to shell script, can i do it with system() or i have any other way to send this variable form c to shell script. |
|
||||
|
The way echo.sh is written it will display just "hello" and not "hello all".
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
const char *str = "hello all";
char cmd[30];
sprintf(cmd, "./echo.sh %s", str);
system(cmd);
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|