System call to different OS using Runtime Class in Java

A

Ayesha Ahsan

Hi,

I use Runtime.getRuntime().exec(command) to make my system call.
For Windows based Dos, i add "cmd /c" before I type in my system
call. So for example make the system call "dir":
String command="cmd /c dir";
Runtime.getRuntime().exec(command);

What is the equivalenr of cmd /c in Unix .

Thank you in advance.
Ayesha
 
P

P.Hill

Ayesha said:
String command="cmd /c dir";
Runtime.getRuntime().exec(command);

What is the equivalenr of cmd /c in Unix .

I'm relatively sure it is:
sh -c

-Paul
 
L

Lew Pitcher

Hi,

I use Runtime.getRuntime().exec(command) to make my system call.
For Windows based Dos, i add "cmd /c" before I type in my system
call. So for example make the system call "dir":
String command="cmd /c dir";
Runtime.getRuntime().exec(command);

What is the equivalenr of cmd /c in Unix .

While I'm unfamiliar with Java's implementation of the system() method, I assume
that it is similar to the standard Unix system() call. /That/ call does not need
'helper' applications to launch the required application, but launches it
directly using one of the execv() calls.

So, the Unix equivalent of your MSWindows "dir" system call would be

String command="ls";
Runtime.getRuntime().exec(command);


--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
 
B

Bill Marcum

["Followup-To:" header set to comp.unix.questions.]
Hi,

I use Runtime.getRuntime().exec(command) to make my system call.
For Windows based Dos, i add "cmd /c" before I type in my system
call. So for example make the system call "dir":
String command="cmd /c dir";
Runtime.getRuntime().exec(command);

What is the equivalenr of cmd /c in Unix .
sh -c would be the closest equivalent, but the syntax of sh is quite
different and "dir" is not a builtin command.
 
G

Guest

Hi,

I use Runtime.getRuntime().exec(command) to make my system call.
For Windows based Dos, i add "cmd /c" before I type in my system
call. So for example make the system call "dir":
String command="cmd /c dir";
Runtime.getRuntime().exec(command);

What is the equivalenr of cmd /c in Unix .

Thank you in advance.
Ayesha

I would use a cross-platform Java call, if one exists. If you want a
list of files in a directory, use File.listFiles() or one of its variants.

BTW, for Windows 95/98 (and I think ME, not to mention the defunct Win
3.1), the command interpreter is command, not cmd. Win XP has both cmd
and command, though I'm not sure of the difference.

HTH,
La'ie Techie
 
T

Tony Morris

Java does not provide the ability to read environment variables.
They may, however, be passed as system properties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top