Page 1 of 1

Need help with batch file

Posted: Thu Feb 16, 2023 6:47 am
by jacdelad
Hello,
I have a batch file with the following content:

Code: Select all

echo startplib >> I:\st1.dat
According to what I know this should only print out "startplib >> I:\st1.dat" on the screeen. However, ">>" seems to be some kind of pipe (I had expected "|") and the output data of "startlib" is saved into "I:\st1.dat".

My questions are:
Why does this not just simply print out the rest of the line after "echo"?
What does ">>" exactly do?

Re: Need help with batch file

Posted: Thu Feb 16, 2023 7:38 am
by normeus
you found the append to the end pipe >>

escape the special characters:

Code: Select all

echo startplib ^>^> d:\st1.dat
or just enclose text in quotes

Code: Select all

echo "startplib >> d:\st1.dat"
Norm.

Re: Need help with batch file

Posted: Thu Feb 16, 2023 9:23 am
by jacdelad
Ah ok. So if st1.dat already exists the new data will just be appended, while | always starts a new file?

Re: Need help with batch file

Posted: Thu Feb 16, 2023 11:14 am
by Marc56us
This is shell commands (aka "DOS" commands) and unix/linux shell

> : create new file or overwrite if exist
echo Hello > txt.txt
echo Hello > txt.txt
type txt.txt

>> : append to file if exist or create new
echo Hello > txt.txt
echo World >> txt.txt
type txt.txt

| : Tee
Help cmd | more
Help cmd | findstr ">"

Re: Need help with batch file

Posted: Thu Feb 16, 2023 11:56 am
by jacdelad
Ah great, thanks very much!

Now, I still don't understand why the "echo"-command is needed. Can you explain that too?

Re: Need help with batch file

Posted: Thu Feb 16, 2023 12:37 pm
by akee
echo is like print in basic.

so print "hello" to the file txt.txt.

> is like createfile() command.
>> is like openfile() command with #PB_File_Append.