(imported topic written by BenKus)
We have received a couple requests for information on how to append a line of text to a file in a custom Fixlet/Task/Action…
Here is example actionscript that appends a line to the “hosts” file on Windows:
waithidden cmd.exe /C echo {“10.10.10.10 test.domain.com %0d%0a”} >> {(pathname of system folder as string & “\drivers\etc\hosts”)}
I didn’t test this so make sure you try it out before using it (and please post if you find any issues)…
Ben
system
June 15, 2009, 6:38pm
2
(imported comment written by choro)
If you need to add a carriage return:
echo. >> “path to dest”
Also, if you need to find and replace F.A.R.T. is a great dos program.
http://sourceforge.net/project/showfiles.php?group_id=44531
We are either Kings or Pawns, of men
BenKus
June 16, 2009, 5:04am
3
(imported comment written by BenKus)
Good point… Here is how to add a line with a carriage return (which is percent encoded as “%0d%0a”):
waithidden cmd.exe /C echo “10.10.10.10 test.domain.com %0d%0a” >> {(pathname of system folder as string & “\drivers\etc\hosts”)}
Ben
(imported comment written by SystemAdmin)
Ben Kus
Good point… Here is how to add a line with a carriage return (which is percent encoded as “%0d%0a”):
waithidden cmd.exe /C echo “10.10.10.10 test.domain.com %0d%0a” >> {(pathname of system folder as string & “\drivers\etc\hosts”)}
Hey Ben … just a quick FYI, we needed to do the same thing and this failed gloriously. Ended up using the following
waithidden cmd.exe /C echo. #>> hosts
waithidden cmd.exe /C echo.1.2.3.4 server1.name >> hosts
waithidden cmd.exe /C echo.1.2.3.5 server2.name >> hosts
…
The first line there was just to make sure I was on a new line, and no spaces after “echo.” and before “>>” means no spaces in the hosts file either. The quotes in yours showed up in the hosts file as did the percent encodes.
BenKus
May 17, 2010, 10:55am
5
(imported comment written by BenKus)
Oops… I made a mistake and didn’t put {} around the expression… It should be something like:
waithidden cmd.exe /C echo {“10.10.10.10 test.domain.com %0d%0a”} >> {(pathname of system folder as string & “\drivers\etc\hosts”)}
I fixed it in the first post too…
Thanks,
Ben
(imported comment written by Shembop91)
Is there a way to do this on a Macintosh?
I want to append text to a file on a Macintosh, but have not found a way listed so far.
(imported comment written by jessewk)
Hi Shembop,
Yes. >> is a universal operator for appending output to a file on unix OSes and it was also adopted by Windows. You can find lots of examples of running shell scripts in our existing Mac content.
Jesse
(imported comment written by fywu91)
Hi Ben,
This did not work for me. No file was created, unless I remove the %0d%0a. What’s wrong?
waithidden cmd.exe /C echo {“10.10.10.10 test.domain.com %0d%0a”} > c:\temp\test.txt
In a relevance query, I found this:
Q: “Hello %01 %02 %03 %04 %05 %06 %07 %08 %09 %0A %0B %0C %0D %0E %0F %20 %21 %22 %23 %24 %25 %26 %27 %28 %29”
A: Hello %01 %02 %03 %04 %05 %06 %07 %08 %09 %0a %0b %0c %0d %0e %0f ! " # $ %25 & ’ ( )
T: 0.028 ms