Assigning a batch file to a button

I have a batch file I want to run on selected files in a given lister (and those selected files only) from a toolbar button. What's the proper way to set it up in the Command Editor? I can get the button to call the batch file -- let's call it "test.cmd" -- but it only works on the first file in the selection, after which it exits.

I don't think there's anything in the batch file causing execution to exit prematurely, as the same thing happens even when the batch file consists only of the single command "echo %1." Please note that I've also tried structuring the button using the control codes that seem the most logical, but to no avail.

Thanks to anyone who can steer me straight.

You can use test.cmd {filepath} to run test.cmd once per selected file, or test.cmd {allfilepath} to run it just once with all filenames on a single command-line.

Thanks, but it still executes only on the first selected file and then exits. What am I missing?


What's in the batch file?

(Please also link your account.)

echo %1
pause

You don't need a batch file to do this. Just use this command in your button (MS-DOS Batch Function):

echo {filepath} pause

Thanks, kundal, but those are just dummy commands intended to help me figure out how to execute a batch file on selected files. The actual batch file I intend to call with the button is more complex, and I'm not sure if the sequence of commands can be written directly into the button code. And since the batch file is already known to be working, I'd prefer to have the button just call it.

[quote]I'm not sure if the sequence of commands can be written directly into the button code.[/quote]You should really try to do that. Replace %1 with {filepath} and see the result. DOpus will create a batch file in your %temp% directory where you can look up what exactly DOpus executes. You'll sometimes see some problems with quotes. You can often get around this by writing @nofilenamequoting to the first line and setting quotes where needed. I'm not an expert with batch files but I was able to adapt some really complex DOS commands to work directly from a button.

It turns out that if you use .cmd instead of .bat as the extension for your batch file, and run it from an MS-DOS Batch Mode button in Opus, then nothing will run after the first .cmd, unless you run it via the "call" command.

So either rename it to test.bat or use "call C:\test.cmd {filepath}" to run it if you want to keep it as .cmd for some reason.

The call command is needed because, to cut a long story short, MS-DOS is poorly designed and arcane. :slight_smile: Opus automatically inserts the call command before .bat files in this situation but not before the rarely-used .cmd files.

If you use test.bat instead of test.cmd with only echo %1 in it (without "pause") it's working for me with the following button code:

@leavedoswindowopen C:\test.bat {filepath}

It works fine with the pause as well (and obviously pauses after each file).

The only important thing here is using .bat and/or using "call".

I've written a lot of batch files over the years that only run when I send the files selected in Opus to the script. Most of the time I'll use the

C:\test.bat {filepath$}

method which as you said runs the script once per file then exits, which for me is just fine in most cases. Occasionally I'll have a reason where I'll need the script to process a block of selected files, then I'll use the

C:\test.bat {allfilepath$}

method.

If you could further explain what the batch file will eventually do, it might help us to make suggestions on the best way to go about it.

I think the question has been answered. These extra posts are just going to make it harder to find the answer, which is now in the middle of the thread. :slight_smile: