1

What is the correct batch file syntax to run command-line application with arguments on windows 7?

C:\KindleGen\kindlegen.exe Htmlpage.html -c2

The bat file is in one folder with page that should be to processed.

2 Answers2

3

Windows uses %1, %2, etc for the argument substitution.

Batch file test.bat contains:

c:\KindleGen\kindlegen.exe %1 -c2

Assuming the -c2 should always be applied

Call it with:

test somefile.html  

If you need to run from the GUI, you can drag the .bat file to your desktop and double click it.

If the file to be processed is always the same, then you don't need the command line args, just put the complete command line in the bat file:

c:\KindleGen\kindlegen.exe Htmlpage.html -c2

If you need to get the user's input for a file name, you could have the .bat ask for it like this:

echo off
set /p fileName=Enter file name:
c:\KindleGen\kindlegen.exe fileName -c2
set /p done=Finished. Press enter...

When you click on that it will open a command window and wait for input, run the command, then wait for enter before closing the command window. Take that last line out if you want it to just close when done.

If you need a script that runs the command for all .html files in the current folder use:

echo off
for %%c in (*.html) do c:\KindleGen\kindlegen.exe %%c  -c2
bitfiddler
  • 2,095
  • 1
  • 12
  • 11
  • Calling bat from Command Prompt is not convenient, I mean run bat file by click on it: so batch file should have page.html name inside. –  Jul 13 '13 at 15:37
  • Are you looking for a bat that will execute the command for the same file each time, for all or certain files in the directory or the user supplies the file name each time? – bitfiddler Jul 13 '13 at 18:42
  • Added some examples for use in the GUI to the answer – bitfiddler Jul 13 '13 at 19:02
  • Execute command for the same file, as I can easy change file name in bat if needed. I use this bat, works for me: `start "kindlegen" C:\KindleGen\kindlegen Pagename.html -c2 -verbose` –  Jul 13 '13 at 19:26
2

Try:

start "" "C:\KindleGen\kindlegen.exe" "Htmlpage.html" -c2
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • Sinse I want read conversion log, I want .bat wait for enter before closing the command window. So this version will be fine: `start "kindlegen" C:\KindleGen\kindlegen Pagename.html -c2 -verbose` `set /p done=Finished. Press enter...` –  Jul 13 '13 at 19:38