- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Can we execute more than one command with pope...
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
Discussions
Discussions
Forums
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
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
тАО03-02-2008 10:51 PM
тАО03-02-2008 10:51 PM
Can we execute more than one command with popen() ?
Can we execute more than one command by using popen() call?
I am gettign an error message When I try to execute the following command
popen("cd /sys/class/scsi_host/host0/device/../driver; pwd", "r").
I am seeing the following error message:
cd: /sys/class/scsi_host/host0/device/../driver: No such file or directory
actually the above command is succesfully executed @ shell prompt but when i try to execute the same command in .c file i am getting the above error.
Can any one debug this?
Your help is appreciated.
Regards
Masthan D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2008 11:30 PM
тАО03-02-2008 11:30 PM
Re: Can we execute more than one command with popen() ?
However, the error you are getting suggests to me that the shell can't find your directory, not that popen() is failing.
popen() simply passes the string to "/bin/sh" and connects it's standard input and output accordingly. If the shell returns what you want then you should be able to read it through popen().
I just tried your "cd ...;pwd" string and it works fine.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2008 11:33 PM
тАО03-02-2008 11:33 PM
Re: Can we execute more than one command with popen() ?
Thanks for quick reply.
Can you try the following command on your linux machine?
popen("cd /sys/class/scsi_host/host0/device/../driver; pwd", "r");
FYI: I am using SLES 10 machine.
Regards
Masthan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2008 11:37 PM
тАО03-02-2008 11:37 PM
Re: Can we execute more than one command with popen() ?
I'll have a little play now!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2008 11:41 PM
тАО03-02-2008 11:41 PM
Re: Can we execute more than one command with popen() ?
See the difference in these two commands.
sh -c "cd /tmp"
and
sh -c "cd /sys/class/scsi_host/host0/device/../driver"
It should be remembered that /sys isn't a real filesystem as such as is merely an export from the kernel. This almost certainly has something to do with it but it certainly requires further investigation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2008 11:46 PM
тАО03-02-2008 11:46 PM
Re: Can we execute more than one command with popen() ?
Actually I think it's a combination of symbolic links and the sysfs filesystem. If you chdir() before popen() it works but you find yourself in the target directory not the symbolic link as such.
IS there another way you can get what you are trying to achieve?