java


Execute “system.exe”,“-get t”


Please help me I used this java code :
public class ClientApplication {
public static void main(String[] args) {
String[] commands = new String[] {"system.exe","-get t"};
try{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(commands);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
System.out.println("Here is the standard output of the command:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {e.setStackTrace(null);}}}
to get information about the system but an exception is detected :
Exception in thread "main" java.lang.NullPointerException.
Please can you help me to execute a command in windows device.
I'm not a Windows expert, but my understanding is that "system.exe" is not a Windows command. So trying to use it as a command like this will not work.
This doesn't explain the NPE, but I am not convinced that the information you have given us about where the NPE is occurring is accurate. But I can tell you that the only way that there is no way that an NPE can be thrown at THIS LINE in the following:
String[] commands = new String[] {"system.exe","-get t"};
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(commands); // THIS LINE
The value of rt cannot be null, the command variable is not null and the array doesn't contain any null values.
In short, either the NPE occurred at a different line, or the code you are running is different to what you have shown us.
Unfortunately ( from your perspective ) I don't have a Windows machine that I can use to experiment with your code.
Finally, this is completely wrong:
} catch (Exception e) {e.setStackTrace(null);}}}
And ... now that I think about what is inside the try block ... this is probably the real place where the NPE is being thrown! The javadoc for setStackTrace says:
Throws: NullPointerException - if stackTrace is null or if any of the elements of stackTrace are null.
OTOH, it makes no sense to setStackTrace there anyway. What are you trying to achieve?

Related Links

Java Program to edit file to select records
JPA to retrieve name-value from child table without using model for child
Spring: Injecting Resource as InputStream into a factory-method
GWT Widget does not allow long-touch-to-copy selections
Serialization third-party classes with Simple XML (org.simpleframework.xml)
save/restore Java swing JList Element to/from MySQL
tomcat closed when i open visualvm_profiler
How to make the java system release Soft References?
Search a string in a file and write the matched lines to another file in Java
How to get Video file summary in java
How to do inclusive range queries when only half-open range is supported (ala SortedMap.subMap)
Modifying Properties files in Tomcat
How to use CellRenderer for GregorianCalendar?
why my website display in FB Login window After Login through facebook?
Thread Suicide on Shutdown? stopping java.util.Timer instance
Weird value of System.getProperty(“os.name”)

Categories

HOME
ms-access
twitter
xamarin
drivers
view
platform-builder
rsync
yahoo-oauth
amortized-analysis
malloc
google-project-tango
windows-server
serverspec
contact
esper
google-translate
adobe-analytics
apache-cayenne
static-libraries
reactcsstransitiongroup
jqwidget
excel-vba-mac
beyondcompare
nhibernate-envers
swingx
reverse-proxy
object-detection
format-specifiers
facebook-access-token
intel-pin
brunch
typo3-6.2.x
kendo-datasource
bosh
typed.js
lxd
mozilla
disassembling
neuroscience
serverside-rendering
libvpx
objectlistview
sqlite2
trim
dism
ws-security
eclipse-scout
quadratic-programming
turbogears
acoustics
taffy
apache-fop
paxos
tizen-native-app
lowpass-filter
forever
np-complete
qtwebview
or-tools
specrun
messenger
color-picker
nxt
etsy
holder.js
bluegiga
ipconfig
ptrace
itextpdf
xna-4.0
r-tree
jms2
fouc
iis-arr
tarjans-algorithm
0xdbe
cakephp-3.1
csquery
device-manager
googlemock
ceil
eol
yorick
hippomocks
comexception
ember-charts
fmod
dataservice
gridcontrol
padarn
sqlperformance
factory-method
unc
gdata-api
armcc
ocx
punbb
xmlspy
inotifycollectionchanged
cxxtest
suppress
ext3
perfect-hash
fixed-width
brewmp
scripting-languages

Resources

Encrypt Message