ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The system call only takes a single string argument. You will need to append the lab5 argument to the "/tmp/lab5.sh" string inside the C code before calling system.
Last edited by neonsignal; 10-27-2009 at 09:35 PM.
int main (int argc, char *argv[])
{
int count;
for (count = 1; count < argc; count++)
{
return system("/tmp/lab5.sh argv[count]");
}
return 0;
}
The result i m getting is
[root@RH100 /]# ./lab5 ad /etc/passwd
This is lab5.sh, running at Tue Oct 27 22:36:21 EDT 2009
It is running on RH100.com
Script being run by
User root
UID 0
who is really root
Called with 1 arguments
-> Argument argv[count] either is not a regular file, or doesn't exist
===========
It should show called with 2 arguments and first one should display not a regular file and second one should display as a file. The problem is parameters are not being passed to shell script properly.
You might need to do a bit of background reading on using strings in C. The language has little native support for strings, so you need to write code and use string library functions to manipulate them (in your example, you might make use of strncat).
You might find this task easier in a scripting language such as bash shell script or perl, which handle strings natively, unless you have particular reasons for wanting to use C.
Last edited by neonsignal; 10-27-2009 at 09:57 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.