aspose file tools*
The moose likes Linux / UNIX and the fly likes Question in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Question in "echo" command" Watch "Question in "echo" command" New topic
Author

Question in "echo" command

Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Hi All,

My requirement is to create a file on the Solaris box that is having the XML in it. I am using "echo" command to create a file with the XML. Below is the command that I am executing from my java code.

or

xml and fileName are the String variables. My problem is that when I have the xml to some string value like

then its working fine in both of the cases; file is being created on the server with xml in it. But when I am passing the actual xml to this command no file is being created and also I can't see any error. Are "<>" symbols in the xml is causing the trouble. Please help me how can I ignore that.
I am using "expect" tool to run the Linux commands from my java code.

Thanks in Advacnce.


Do not wait to strike till the iron is hot; but make it hot by striking....
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

I am very, very confused here. It appears that you have a string containing text in XML format and you want to write it out as a file.

Why go to all the trouble of using a shell command to do that when you can use the Java I/O classes to write the file directly???

However, as far as it goes, I/O redirection (the ">" command operator) does not work in Runtime.exec and similar Java command-line control functions. You have to actually redirect the stdout stream of the profess itself, which is not quite as simply as coding a ">".

Also, although it probably doesn't apply here, the Solaris version of the "echo" command differs somewhat from the Linux version.


Customer surveys are for companies who didn't pay proper attention to begin with.
Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Thanks for your time Tim.

Yes Tim, you are right. I am having a string containing text in XML format and and I want it to write to a file.
The application is running on Windows machine, What I am doing:
1. Logged in on the Solaris box from Windows Machine
2. now using the command echo to create a file as I mentioned earlier(in the user's home directory).

As I said earlier I am using expect to login and writing purpose

I am not sure how I am going to write a file over ssh.
Thanks.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

Let's see if I understand.

You have a webapp on a Windows box and you want to create a file on a Solaris box, right?

I'm afraid that you can't just "exec()" a login followed by an "exec" echo. Each exec() creates (and destroys) a runtime environment, so when the first command completes, it logs that environment out (and destroys it!). So the "echo" ends up running on the Windows box, instead!

There are (at least!) 2 ways you can do this. One is to publish a netshare on the Solaris box that allows access to the target directory. Then you can use plain old Java I/O to write the file on the network drive. You can use either CIFS or NFS for this. NFS requires NFS client software to be installed on the Windows box, CIFS is Windows Networking, and it requires server software (Samba) to be installed on the Solaris box. I believe you also have to purchase an additional bit of software for Solaris to act as a CIFS server (in Linux, it's part of the basic Samba and it's free).

Another way you can do this is to write the file locally and then ship it to the Solaris box. In this case, again, you'd use the Java I/O to write a Windows file, then copy it to the Solaris host using FTP or SCP. You'd probably want to write a script (BAT file) to manage the copy process and exec the script.
Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Thanks for your time and suggestion Tim, this is a desktop application actually.
Now, I am trying to use FTP for the file transfer, as you suggested; I hope I will get success..

Thanks again for your time.
 
 
subject: Question in "echo" command