• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 22510
122
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic