Results 1 to 4 of 4
Thread: running unix command from java
- 07-09-2012, 01:45 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
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 = 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
ksh: :> /t3/envs/dmdev3/test/file_list.txt: not found
:(:(:(
below is my java code snippet that i use,
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.
- 07-10-2012, 07:30 AM #2
Re: running unix command from java
Have you tried using this line of code? :
If you do not know how to use this properly, a quick google search will provide you with a bunch of examples of how to use this.Java Code:Process child = Runtime.getRuntime().exec(command);
This site had a good one as well.
Running system commands in Java applications | java exec example | devdaily.com
I would try to execute you command, but I would not want to access your ssh server.My API:Java Code:cat > a.out || cat > main.class
- 07-10-2012, 10:14 AM #3
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
Re: running unix command from java
- 07-10-2012, 10:17 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: running unix command from java
I'm guessing that is the equivalent of the line the OP has given, where runEnv is the Runtime and procTemp is a Process.
For the OP all I can suggest is going through this article at JavaWorld which covers a lot of things you need to know about how Runtime exec() works (and sometimes doesn't).Please do not ask for code as refusal often offends.
Similar Threads
-
Running object-oriented in Unix
By justOne in forum New To JavaReplies: 3Last Post: 03-28-2012, 08:22 PM -
running command prompt using java
By xclaim in forum New To JavaReplies: 1Last Post: 01-14-2010, 03:46 AM -
Problem while executing unix command having \&\& symbol
By suryahota in forum New To JavaReplies: 0Last Post: 06-20-2008, 09:02 AM -
Filter a file in java (unix cut command equivalent)
By marcosabel in forum New To JavaReplies: 0Last Post: 02-11-2008, 07:26 PM -
Running java program with arguments in Unix"
By gvi in forum Advanced JavaReplies: 2Last Post: 11-08-2007, 07:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks