if you're using sh try just putting the who in to be executed. I tried
this on my solaris server and it worked. (but when i tried running it from
a bash shell on solaris it didnt work..only from sh)
import java.lang.*;
import java.io.*;
class ExecuteCmd {
/** execute arbitrary OS command
@param String[] command to be executed by the OS
@return void
@throws N/A
*/
public static void main(String args[]) {
try {
String cmd = "who";
System.out.println("Going to execute : " + cmd);
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
String s;
System.out.println("Here is the standard output of the
command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if
any):
\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
//wait for end of process and get exit status
int status ;
status = p.waitFor();
if (status != 0) {
System.out.println("The command returned a status of " +
status);
}
} catch (InterruptedException intexc) {
System.out.println("Interrupted Exception on waitFor: " +
intexc.getMes
sage());
} catch (IOException e) {
System.out.println("ExecuteCmd.main() : " + e);
} catch (Exception e) {
System.out.println("ExecuteCmd.main() : " + e);
}
}
}
On Tue, 27 Aug 2002, Raju Lokhande wrote:
> I tried this on Sun Solaris and I got another issue. The same error happened on the
>command line prompt.
> servername:[/export/home/rlokhand]/usr/bin/sh /usr/bin/who
> /usr/bin/who: syntax error at line 1: `(' unexpected
> If I execute /usr/bin/who it executes fine. Same thing with other unix commands like
>"ls".
> If I put this in a shell script and then execute that script using
> /usr/bin/ksh "full path-name of the script"
> this works fine.
> But I do not want to maintain another shell script. Is there a way around this?
> Thanks
> Raju Lokhande
>
>
> >>> [EMAIL PROTECTED] 08/22/02 12:42PM >>>
> Hi,
> I have the following code in a servlet
> String tmp = "filename";
> prPrintout pr = new prPrintout();
> boolean hmm = pr.createFile(tmp +".html");
> try {
> Runtime rt = Runtime.getRuntime();
> Process p = rt.exec("/usr/local/bin/html2ps -o \""+tmp+".ps\"
> \""+tmp+".html\" ");
> p = rt.exec("lpr -Plp1 \""+tmp+".ps");
> System.out.println("printing");
> } catch(IOException e) { System.out.println(e);}
>
> and what its suppose to do is run html2ps on the html file i created with
> createFile, converting the html file to a ps file and then pringing the ps
> file.. but it doesnt do the converting nor the printing.. (when i do the
> commands via command promt it works fine, so its something in my code that
> i'm forgetting about..) tho it doesnt throw an exception and it does print
> my System.out.println("printing"); line.. Anyone know why?
>
> Thanks
> Sohaila
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
>
>
> *************************************************************************
> This message, together with any attachments, is intended only
> for the use of the individual or entity to which it is addressed. It
> may contain information that is confidential and prohibited from
> disclosure. If you are not the intended recipient, you are
> hereby notified that any dissemination or copying of this
> message or any attachment is strictly prohibited. If you have
> received this message in error, please notify the original sender
> immediately by telephone or by return e-mail and delete this
> message along with any attachments, from your computer.
> Thank you.
> *************************************************************************
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html