Need help with batch file

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
jacdelad
Addict
Addict
Posts: 2029
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Need help with batch file

Post 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?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
normeus
Enthusiast
Enthusiast
Posts: 475
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Need help with batch file

Post 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.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
jacdelad
Addict
Addict
Posts: 2029
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Need help with batch file

Post by jacdelad »

Ah ok. So if st1.dat already exists the new data will just be appended, while | always starts a new file?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Need help with batch file

Post 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 ">"
User avatar
jacdelad
Addict
Addict
Posts: 2029
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Need help with batch file

Post by jacdelad »

Ah great, thanks very much!

Now, I still don't understand why the "echo"-command is needed. Can you explain that too?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
akee
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Need help with batch file

Post 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.
Post Reply