nhabbott nhabbott - 5 months ago 46
Bash Question

Converting .sh to .bat

I have a

.sh
file that I would like to convert to a
.bat
file. Below you can see my shell script and below that my sad attempt to convert the shell script to a batch file. I was able to covert some parts but other parts "stumped" me, like trying to echo the output of the
node pong.js $1
command to
__pongjs_output.txt
.

# Run a .php file both on pong.js and php and diff the output.

# Run on pong.js
node pong.js $1 > __pongjs_output.txt

# Run on node and replace some property names.
php $1 > __php_output.txt

echo "$1:"
diff __pongjs_output.txt __php_output.txt && echo "ok"

rm __pongjs_output.txt __php_output.txt


My attempt at converting the shell file to a batch file:

@ECHO off
REM Run a .php file both on pong.js and php and diff the output.

REM Run on pong.js
ECHO node pong.js %1 > __pongjs_output.txt

REM Run on node and replace some property names.
ECHO php %1 > __php_output.txt

ECHO %1:
FC __pongjs_output.txt __php_output.txt
IF errorlevel 0 ECHO ok

DEL __pongjs_output.txt __php_output.txt

Answer

Try this (remove ECHO from before node and php):

@ECHO off
REM Run a .php file both on php.js and php and diff the output.

REM Run on pong.js
node pong.js %1 > __pongjs_output.txt

REM Run on node and replace some property names.
php %1 > __php_output.txt

ECHO %1:
FC __pongjs_output.txt __php_output.txt
IF errorlevel 0 ECHO ok

DEL __pongjs_output.txt __php_output.txt