• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Question in "echo" command

 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 26538
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26538
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic