Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to read a file on Unix into a file on windows or into a string builder  RSS feed

 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to read a file on a remote server, which is on a Unix box. I don't mind if I can read it into a Stringbuilder or a file. The normal

which works well on windows would work for me.

So I am using SSH to connect, and then I am running commands
eg Cat /var/log/logfile.

I can view the content of the file on the console, but I cannot save it to a string or write to the file. I am having a nightmare with Converting the OutputStream to String or even FileOutputStream


here is a snippet



So my question is this, after running the command, I can see the command and the returned stuff in the console, but I am not having any luck writing the content into the file. I am able to write the first line into the file - out.write((command+";echo \'z4a2ce4f3317Z\'").getBytes()); this writes the command into the file, but the next lines which contains stuff returned is not copied to the file




 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps I am misunderstanding all of that, but if you want to write your data to a String instead of a File, then why not just write to a StringWriter instead of a FileOutputStream?
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will have a look at stringWriter. Thanks
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still unable to solve this, all I want to do is to write the bytes in the outPutstream as a String. ie

run a Linux command, eg ls -l, and get the result / output stored in a String. Please help
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't seem to be the same question, but here's one way you could run "ls -l" and capture the output in a string:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!