• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java and PSExec

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello...

I am trying to read free space available on remote servers. I am using java and psexec for this. I have written code and am trying to invoke a batch file at the same time passing a variable to it. The batch file has psexec commands to determine the free space. I have 2 issues here.
1) when i am trying to invoke the batch file and pass server name as parameter, i get a message Error: ReadError
2) I am having trouble assigning the parameter that i am passing to a variable in the batch file.

Below is my java code:

import java.io.*;
import java.lang.*;
import java.util.*;

class PsexecnJava
{
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("textfile.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String string1;
while ((string1 = br.readLine()) != null)
{
System.out.println ("Now logging onto Server: "+string1);
readVal(string1);
in.close();
}
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
public static void readVal(String st)
{
try
{
Runtime.getRuntime().exec("test1.bat st");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yuri Pen wrote: I have 2 issues here.



You've got more issues than that. Take a few moments with this article that discusses the use and pitfalls with Runtime.exec().
 
Yuri Pen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic