0

I have a strange problem with my windows .bat files a 0 is coming before < while executing. I don't know where its getting it from. Below is the contents of the batch file date1.bat

set mysql="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe"
set progDir="D:\BigData\14.Nodejs\3.Firebase"
set dataDir=D:\BigData\14.Nodejs\3.Firebase\data

%mysql% -ualpha -pbeta test < "%dataDir%\LatestData - Q -201811 - INSERT DMLs.sql"

Issue I am referring to comes in the line

%mysql% -ualpha -pbeta test < "%dataDir%\LatestData - Q -201811 - INSERT DMLs.sql"

Below is the output

D:\BigData\14.Nodejs\3.Firebase>date1

D:\BigData\14.Nodejs\3.Firebase>set mysql="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe"

D:\BigData\14.Nodejs\3.Firebase>set progDir="D:\BigData\14.Nodejs\3.Firebase"

D:\BigData\14.Nodejs\3.Firebase>set dataDir=D:\BigData\14.Nodejs\3.Firebase\data

D:\BigData\14.Nodejs\3.Firebase>"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe" -ualpha -pbeta test  0<"D:\BigData\14.Nodejs\3.Firebase\data\LatestData - Q -201811 - INSERT DMLs.sql"

In the last time you can see a "0<" not sure where its getting that 0 from. Is there a way to avoid it.

I am just trying to run DMLs in multiple files via windows batch.

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
bobby.dreamer
  • 366
  • 4
  • 19
  • 1
    Please read Microsoft article about [Using command redirection operators](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490982(v=technet.10)). Windows command processor `cmd.exe` replaces redirection operator `<` by `0<` before execution of the command line and `>` by `1>`. This cannot be avoided and is absolutely correct. The redirection operators `<` and `>` should be for that reason never written in a batch file or on Windows command line with `0<` or `1>` to redirect __STDIN__ or __STDOUT__ handle of an application or command. – Mofi Nov 03 '18 at 08:31
  • 1
    I recommend also reading the answer on [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) It explains the difference between `set variable="value"` and `set "variable=value"`. – Mofi Nov 03 '18 at 08:33

2 Answers2

1

What you are viewing is the echo of commands as how the interpreter evaluates the code.

  • Handle 0 is Stdin which < redirection is interpreted as from handle 0<.
  • Handle 1 is Stdout which > redirection is interpreted as from handle 1> or to handle >&1.
  • Handle 2 is Stderr which 2> redirection is interpreted as from handle 2> or to handle>&2.

Handles 3 to 9 are auxiliary handles unique to batch-file.

michael_heath
  • 5,262
  • 2
  • 12
  • 22
1

0 means standard input. 0< myfile means send the contents of myfile to standard input. < myfile is shorthand for 0< myfile. The 0 is doing no harm and you don't need to get rid of it.

BoarGules
  • 16,440
  • 2
  • 27
  • 44