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.
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....
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.
An IDE is no substitute for an Intelligent Developer.
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.
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.