3

I'm working on a project that require me to use window task scheduler to execute mysql query, this is the batch file content:

mysql -ufoo -pbar -D %1 < %2

when I tested the batch file via cmd:

task_sheduler.bat dbName pathToSqlFile

I get:

mysql -ufoo -pbar -D dbName  0<pathToSqlFile

I just want to say that its working, my question is what is about the extra space and the 0, where did they came from?

  • The extra space is between the dbName and 0
  • I'm using Windows 7 Ultimate Service Pack 1 (x64)

2 Answers 2

3
+50

I assume your Batch file does NOT have an @echo off command, so you refer to the echo of commands that appear in the screen when a Batch file is executed. The display of these commands frequently include additional characters that cmd.exe inserts to display exactly the executed commands.

In the case of redirections, <input is a short form of Stdin redirection, and the number of Stdin is zero, so the real redirection is 0<input. The same happens with >output, that is echoed as 1>output. cmd.exe also remove multiple spaces from the original code and insert needed ones in order to clearly show the executed commands.

If you want not to see these command expantions, just insert an @echo off command at beginning of your Batch file.

Sign up to request clarification or add additional context in comments.

3 Comments

if cmd.exe also remove multiple spaces from the original code and insert needed ones in order to clearly show the executed commands, shouldn't it remove my space or give up the extra space it adds to prevent hi.exe0 < myfile (from the other answer).
cmd.exe have a certain behaviour about this point. For example, in (mysql -ufoo -pbar -D dbName<pathToSqlFile) a space is always inserted before the 0< and ), but the digit is never separated from the <. You may do other tests to find out other cases, if you wish...
I did test with (), I also understand the logic behind it its thank you.
1

cmd prefixes all redirection commands by the default handle if none is provided. The handles are defined here. 0<file thus means that we want file to be redirected to standard input. The extra space is there to prevent a command like hi.exe<myfile from being wrongly interpreted as hi.exe0 < myfile

1 Comment

Hey @Lanting, thank you for your answer I did use the link you help me understand the logic behind the extra space, thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.