- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: command execution on HPUX from a Java process
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
тАО10-24-2008 02:08 AM
тАО10-24-2008 02:08 AM
I need to execute a command (ls -1
I have written the following test code:
String s = "ls -1 /tmp/prova*";
try {
Process proc = Runtime.getRuntime().exec(s);
BufferedReader read=new BufferedReader(new InputStreamReader(proc.getInputStream()));
while(read.ready())
{
System.out.println("line = " + read.readLine());
}
proc.destroy();
}catch(IOException e) {
e.printStackTrace();
}
but nothing is printed.
If I remove "*" character from the command:
String s = "ls -1 /tmp/prova";
it works fine.
How can I manage such character?
Thanks
Solved! Go to Solution.
- Tags:
- Java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2008 02:24 AM
тАО10-24-2008 02:24 AM
Re: command execution on HPUX from a Java process
Bottom line, the wildcard is expanded by the shell, but you only run the ls program.
You may want to use something like "sh -c \"ls -1 /tmp/prova*\"". But be aware that this creates two processes, one for the shell and another one for ls.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2008 02:51 AM
тАО10-24-2008 02:51 AM
Re: command execution on HPUX from a Java process
"sh -c 'ls -1 /tmp/prova*'"
but without success.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2008 03:49 AM
тАО10-24-2008 03:49 AM
SolutionTry to change
String s = "ls -1 /tmp/prova*";
to
String cmd[] = {
"sh",
"-c",
"ls -1 /tmp/prova*"
};
specifying explicit arguments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2008 03:53 AM
тАО10-24-2008 03:53 AM
Re: command execution on HPUX from a Java process
Many thanks