954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Possible to use system(); in Java?

Hi,

I am new to Java.

Id like to know if I can use system commands in Java applications. Thanks in advance,


Jan

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

Hi,

I am new to Java.

Id like to know if I can use system commands in Java applications. Thanks in advance,

Jan

Sure

System.out.println();

:lol:

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

no....I mean like system("reboot");

Can I use em?

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

whatever happened to trying?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Is there even a portable, cross platform way to perform a reboot in java?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Read the API doc for Runtime.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

here is output
[jan@localhost hello]$ javac helloJava.java
----------
1. ERROR in helloJava.java (at line 7)
System("xmms");
^^^^^^
The method System(String) is undefined for the type helloJava
----------

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

yup, that's not the way to call things outside the JVM...

Is there even a portable, cross platform way to perform a reboot in java?

Of course not, as there is no platform independent way to do it at all (except for pulling the powerplug, and that's assuming there's no UPS attached).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Look into the Runtime.exec methods, as masijade suggested

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You