Link to home
Start Free TrialLog in
Avatar of bschiel
bschiel

asked on

Batch file question

so I have the following command that works at the command prompt
 
sqlite3 mydb.db < udpate.txt

or

sqlite3 mydb.db < reset.txt

because I have to do this often for testing I want to batch these commands.

When I do the command line interpreter reads the < as a less than sign and puts a 0 infront.  So my actual script file appears now as:
sqlite3 mydb.db 0< udpate.txt

Anyone know how to have this interpreted correctly?

thanks
Avatar of duttcom
duttcom
Flag of Australia image

You could try escaping the less-than sign with three carets -

sqlite3 mydb.db ^^^< udpate.txt
Avatar of ThomasMcA2
ThomasMcA2

The redirect arrow (<) is a common DOS method. I've been writing DOS batch files for over 20 years, and I've never seen that behavior. Are you sure it's not your text editor adding that extra character? Can you remove the extra character in your text editor? Try these ideas:

From a DOS prompt, type the contents of your batch file to the screen:
type your_batch.bat

Open in new window

Is the character displayed on the screen?

If you have echo off or @echo off at the top of your script, comment it out with REM, then try again. The script will echo each command on the screen. Is the extra character still there?

If you still can't get rid of the extra character, attach your batch script to your reply.
Avatar of bschiel

ASKER

I rewrote the batch file using copy con and get the same results.  

I will try the ^^^ route in the morning and report back.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice reference, Bill, I bookmarked that.

My point is that although 0 represents keyboard input, there is no automated process that replaces < with 0<, thereby breaking redirection.

After rereading the OP, it looks like the 0 is part of the script:
So my actual script file appears now as:
sqlite3 mydb.db 0< udpate.txt

If so, just delete the 0, save the script, then rerun it.

If that doesn't fix it, please attach screenshots of the problem. Include the following screenshots:
1) The script itself, opened in Notepad
2) The "type" command that displays the script in the console
3) The command prompt where you run the script so we can see the results and/or errors

Tom
Avatar of bschiel

ASKER

So it turns out that the sqlite program solves this issue for me.  Just found out there is a switch on the exe that solves this problem.  sqlite3 -echo will use the stdout to display the commands feed to it.  So now I see exactly what I want to see and can verify what I am feeding my DB when i combine it with the @echo off.

Thanks all.