|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
[SOLVED] running unix command from java
Hi All, I have been struggling for a week trying to run a unix command from my java program. the unix command is: Code:
ssh dmdev3@tsapid01-zt3d01 ':> /t3/envs/dmdev3/test/file_list.txt' when i try to run this command directly on my unix console, it works perfectly. but when i try it form my JAVA program, i get the below mentioned error Code:
ksh: :> /t3/envs/dmdev3/test/file_list.txt: not found ![]() ![]() ![]() below is my java code snippet that i use, Code:
procTemp=runEnv.exec(strShellCmd); where strShellCmd contains the entire unix command as a single string requiring your help at the earliest cause i'm in such a desperate situation. Thanks in advance, Madhu.
Last edited by zaxxon; 07-09-2012 at 07:56 AM.. Reason: code tags, see PM! |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Please don't cross post the same question across multiple forums, it dilutes effort.
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
i am sorry. was a bit confused on the correct location of the topic.
rest assured it wont happen again. ![]() |
|
#4
|
|||
|
|||
|
Quote:
First impression is that the command would be better placed in Shell Script. What (in words) are you expecting the command to do. It appears to just execute a null command on a remote server. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
The /t3/envs/dmdev3/test/file_list.txt file is (should be) cleared by this command.
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Code:
private boolean executeShell(String strShellCmd) {
try {
procTemp=runEnv.exec(strShellCmd);
//read the output from shell console
BufferedReader brShellOP = new BufferedReader(
new InputStreamReader(procTemp.getInputStream()));
String strShellOP = null;
while ((strShellOP = brShellOP.readLine()) != null) {
System.out.println(strShellOP);
}
brShellOP.close();
// catch error from shell console (if any)
BufferedReader brShellError = new BufferedReader(
new InputStreamReader(procTemp.getErrorStream()));
String strShellError = null;
while ((strShellError = brShellError.readLine()) != null) {
System.out.println(strShellError);
}
brShellError.close();
// wait for the process to finish
try {
intExitVal = procTemp.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//returns false if shell console throws error
if(intExitVal!=0){
return false;
}
return true;
} catch (IOException ioEx) {
System.out.println("error in executeShell().IOException");
ioEx.printStackTrace();
return false;
}
}this is the entire method that does the execute operation. Let me know if you require any other inputs for getting my issue solved. PS: i'm new to this executing-unix-from-java thing. Thanks a tonne, Madhu. |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Use
cp /dev/null /t3/envs/dmdev3/test/file_list.txt
|
| Sponsored Links | ||
|
![]() |
| Tags |
| java, unix |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| running unix command from java | madhu_sharan | UNIX for Advanced & Expert Users | 0 | 07-09-2012 06:48 AM |
| [Solved] save the return value of a unix command | peuceul | Shell Programming and Scripting | 3 | 12-01-2011 09:13 AM |
| Exception Signal 11 while running JAVA code in UNIX | satish2712 | Programming | 0 | 08-11-2008 02:08 AM |
| exit status running java classpath in unix shell | mmcds | Programming | 2 | 08-02-2007 10:06 PM |
|
|