- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Problem with argv
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 01:24 AM
04-19-2001 01:24 AM
Now my problem is this:
I have this little script that allows to an user to execute "My_shell_script.sh"
with root privileges:
_____________________________________
#include
main()
{
system("/home/My_shell_script.sh");
}
_____________________________________
But the script it would have to be run (in enviroment Unix) with two parameters, inserted by the user when he run the script:
./My_shell_script_compiled $1 $2
So I've tried to modify My_shell_script.sh:
____________________________________________
#include
char * argv[1];
main()
{
system("/home/My_shell_script.sh $argv[1] $argv[2]");
}
___________________________________________
and then run:
./My_shell_script_compiled $1 $2
as another user, but (as I thought)it doesn't work!
Some errors:
chmod:can't access [1]
ksh: [2]: Arguments must be %job or process ids
Please forgive my syntax but I'm not C expert
;-)
Could you help me?
Thanks,
Sergio
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 01:35 AM
04-19-2001 01:35 AM
Re: Problem with argv
Use sprintf!
--------------------
int main(int argc, char **argv) {
...
char strCommand[256];
sprintf(strCommand, "/home/My_shell_script.sh %s %s", argv[1], argv[2]);
system(strCommand);
...
}
-------------------
Hope this helps,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 01:42 AM
04-19-2001 01:42 AM
Solutionif you only want to run you script you should better use the execlp() call:
#include
main(argc,argv)
int argc;
char **argv;
{
execlp("/home/My_shell_script.sh", argv);
}
Other solution for only 2 parameters:
#include
main(argc,argv)
int argc;
char **argv;
{
char cmdbuf[1024];
sprintf(cmdbuf, "/home/My_shell_script.sh %s %s", argv[1], argv[2]);
system(cmdbuf);
}
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 02:46 AM
04-19-2001 02:46 AM
Re: Problem with argv
To Rik: This is the error that I have when compile your script:
(Bundled) cc: "Myscript.c", line 2: error 1705: Function prototypes are an ANSI feature.
- Probably 'cause I haven't ANSI C on my HP-UX.
Thanks however.
To Andreas: This is the error that I have when run your first script:
chmod: can't access {?{?{?^{?:{?F{?P{?`{?i{?|{??{??{??{??
- (???)
Very good instead your second script. It works!
:-)
Thank you very much.
Sergio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 04:06 AM
04-19-2001 04:06 AM
Re: Problem with argv
the mistake at my first code was execlp(..)
It has to be execvp(...)
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2001 04:16 AM
04-19-2001 04:16 AM
Re: Problem with argv
The error you had with my program is that you do not have the ansi c compiler. Use K&R style function prototypes (Andreas's examples) instead.
For the rest, my code should have worked!!
Bye.