We help IT Professionals succeed at work.

Excecuting system commands...

mitra_subhasis
on
How I can execute a system command within a java program. For example, as in C under Unix, we can execute system command by

system("command");
ie. for clearing the screen we use
system("clear");
etc...

How I can do the same in java?

Subhasis.
Comment
Watch Question

Hey Mitra
Use Runtime.exec() format to executate your shell commands.
Not all commands are supported
Shyam
Commented:
To be more precise :

Process p = Runtime.getRuntime().exec("your command goes here");

From this Process object you can obtain the InputStream, OutputStream, ErrorStream to read/write from them when you are executing your command.

Author

Commented:
yes, satisfactory.

Subhasis

Explore More ContentExplore courses, solutions, and other research materials related to this topic.