• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java and PSExec  RSS feed

 
Yuri Pen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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();
}
}
}

 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!