I write the following VB script in order to run commands from WIN XP on Linux machine and redirect the output command to out.txt file ( under C:\ )

My VB script I print the /etc/hosts file from Linux machine in to out.txt file

Script works fine but I have one problem:

/etc/hosts file was printed in out.txt file with one long line , in place of three lines

Example: (out.txt)
      localhost  MY_IP LOOP

In place to print the following host file in out.txt      localhost  MY_IP LOOP

MY VB script

Const TARGET_HOST = ""
const PATH =  "cat /etc/hosts" 
const LOGIN = "root"
const PASS = " dgdgd "
Const PLINKPATH="""C:\dir1\plink.exe"""
Set Sh = CreateObject("WScript.Shell")

CMD = " echo y | " &   PLINKPATH  & " -ssh -pw " & PASS & LOGIN & "@" & TARGET_HOST & " " & PATH 

Sh.Run "cmd /k" & CMD &  " > ""C:\out.txt""" , 1, True

Please advice what I need to fix in my VB script in order to print the correct hosts file ( line by line ) and not as one long line ?

  • you really should troubleshoot things then you'd see that a file with a letter and a new line in linux, is smaller than a file with a latter and a new line in windows. In fact if in windows you do echo a>file1 then you see the file is 3 bytes, and you could ask the question -why-. And find out why. Windows using CRLF is extremely well known. if you ever read up about carriage return you'd probably learn windows uses it and linux just uses LF. i'd think one should run into that fact dozens of times. – barlop Sep 1 '13 at 21:52

Linux systems use Line Feed for line breaks, whereas windows uses Carriage Return + Line Feed. http://en.wikipedia.org/wiki/Newline

In your case, I would run PATH through sed, to replace the LF's with CRLF's

Const PATH = cat /etc/hosts | sed -e 's/$/\r/' 


  • I haven't read his whole question, and it's shocking that a person(the questioner apparently) could know vbscript and where the hosts file is in linux, and not know about CRLF in windows and LF in linux. but anyhow, you write "replace the LF's with CRLF's" Then you write 's/$/\r/' what use would that replacement be - you're saying put CR at the end. that isn't used by any OS. it's either \r\n(CRLF) or it's \n(LF). never just \r(CR). and your sed replacement just puts a CR there. – barlop Sep 1 '13 at 21:46

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.