Using {Rs} or {dlgstring} to pass arguments to a program

When using the external control codes {Rs} or {dlgstring} to pass strings to a function, how are the strings sent to the program? I'm trying to create an Opus button that will run the selected program in a command prompt box and keep the box open. That part is easy enough:

/K being the command-line argument for cmd.exe to keep the window open after the program quits.

However, when I try to run a program that requires arguments to be passed, this button obviously does me no good. So I created a second button with this command:

Which mostly works. However, there is a program that I use quite frequently, which is my main inspiration for creating this button. It doesn't work with this setup. The arguments I need to pass are:

It seems the quotes get screwed up using the button code shown above. Using that code and those arguments, the result is an open command prompt giving me the error: 'C:\Documents' is not recognized as an internal or external command, operable program or batch file.

Any ideas on how to pass quotes as an argument in this manner? Thanks in advance!

--chriscrutch

I don't quite follow you. You mentioned a "program" however your button opens a CMD console which by itself does nothing until you feed it more commands. Are you talking about a batch file? A specific program that needs arguments sent to it in a particular way? If so, we'd need to know what way it needs those arguments presented.

FWIW I have a simple batch file that I call with this button command:

D:\Mine\cmd\Test.bat C:\temp ""

In the batch file are only these three lines:

@echo off
echo %*
pause

The first and third lines in the batch file aren't important to this discussion, however the middle one echoes exactly what Opus sent to it. And with my button command above, it echoes exactly what you asked for

C:\temp ""

So what am I missing?

John

I think you need to add more quotes. :slight_smile:

Try typing """" into the dialog prompt to see if that works. Failing that, try six quotes (two for the start and end of the argument and two doubled-up quotes to produce two quotes in the commandline).

It's probably worth making it work from a command prompt first, then making it work from an Opus button. That way you have less programs potentially removing/interpreting the quotes in the commandline and can work out which commandline you need to generate and then separately work out how to generate that commandline from an Opus button.

@JohnZeman

I'm not using batch files. I have several different command-line programs spread across several different directories that I use on a regular basis. Instead of navigating to their directory, using a "Command prompt here" button, and then typing in the program's name and arguments to run, I wanted to create a button that would do all that automatically, regardless of which of these many programs I feel like running at the time. That's where the {f!} part of my button comes in. I find a program, select it in my lister, and run the button. Double-clicking some of these programs brings up a command prompt which is immediately killed when the program terminates (especially if I screw up the argument syntax :smiley: ), leaving me no time to review the output. I want a button that will automatically open a command prompt, run the program, with arguments if required, and keep the command prompt open so I can review the output. Hence the "cmd.exe /K" reference. Somtimes I want to do this with program A, sometimes with program B, so I can't create a button with a specific program hard-coded into the commands. Normally, the button I created asking for arguments works just as I hoped it would.

is great. The only problem I've come up with so far, is when quotes must be passed as part of the argument. I've found it with one particular program, although I assume it to be true of any program requiring quotes as arguments. Using movefile by Sysinternals, I can direct a file or directory to be deleted at the next boot by running

The quotes are neccessary. When I try to put the quotes into my dialog, they seem to get messed up when passed as arguments. Your example runs a specific batch file with specific arguments hard-coded into the button's execution. My hope is to create a button which asks for arguments and passes them properly. Sometimes I don't want c:\temp to be deleted at boot, sometimes I want another directory. Sometimes I only want to move a file instead of delete it, in which case the quotes are NOT necessary, and the command line would be

I don't want to have to hard-code a button for every conceivable argument combination. I hope I've cleared my problem up and made it more specific. Probably not, though. :slight_smile:

@Nudel:

I tried three, four, five, and six quotes. I tried enclosing the entire argument set in quotes ("c:\temp """). I tried enclosing four quotes in quotes ("c:\temp """""). All produced the same output. I can get these arguments to run in the command prompt, no problem. Running from the c:\ prompt

runs the program as expected with the arguments correct. I just can't figure out where DOpus is putting quotes when I use them as part of the {dlgstring} control code. Nor can I figure out any way to find out where DOpus is putting them.

You could use my Doptest program ([url]DopTest - Test what command lines are generating]). You can give it any arguments you like from an Opus button and it will output to the cli the actual string Opus has created.

Forgive me, I can't quite figure out how to use your doptest program.

--chriscrutch

Did you read doptest.txt? It's pretty simple - just replace whichever program you are using and having trouble with. eg;

You're trying to get this line working:

cmd.exe /K {f!} {dlgstring|Arguments?}

So you would replace cmd.exe in the button with doptest.

doptest.exe /K {f!} {dlgstring|Arguments?}

As per the doptest.txt a couple of special command line arguments can be added to the line which doptest will interpret and modify it's output.

When I replace cmd.exe with doptest.exe, my button doesn't bring up the dialog box asking for arguments, which is essentially the only thing I need to look at. Running

produces, as a result from doptest, with no DOpus dialog coming first,

[quote]"C:\PathToDoptest\doptest.exe" /k {f!} {dlgstring|Arguments?}
Press any key to continue...[/quote]

which doesn't help me in diagnosing anything in my button.

Running

outputs, through doptest, exactly what I'd expect to see. When I add the {dlgstring} control code, it seems to send doptest for a loop, which makes sense.

Am I still missing something? If so, please feel free to call me an idiot.

--chriscrutch

Well I have no idea what you are doing wrong. It works fine for me with your command line.

Try copying and pasting this button to your toolbar. The only thing you should need to change is the path to doptest (remembering to enclose the path in quotes if it contains spaces).

<?xml version="1.0"?> <button display="label" effect="gray"> <guid>{90A3D9A8-8CED-4385-A319-EA2437531303}</guid> <label>Doptest</label> <icon1>84</icon1> <function type="normal"> <instruction>"D:\Dos\doptest.exe" /k {f!} {dlgstring|Arguments?}</instruction> </function> </button>

Not sure why doptest doesn't work for you but, ignoring that for now, I had a look at your cmd.exe problem a bit more and I think cmd.exe is doing something odd with the quotes...

What about doing it another way, without using cmd.exe? You can make a button with function type MS-DOS Batch Function (that's the important part that gives you an output window and allows pause to work) which runs this command:

{f!} {dlgstring|Arguments?}
pause

You can then type "" into the dialog box and it seems to work, and the output window remains until you press the spacebar.

I'm fighting a head code today so I hope I can muddle my way through this.

First off FWIW if it were me I'd do it the way you do not want to do it by assigning a button to each external command line program. That's actually the way I do it and have quite a number of buttons set up that way and they work very well for me.

But to address the way you want to do it, to solve the problem I'd go this route. By the way this assumes you are using at least Windows NT or a newer version of Windows, my suggestion below will not work on a Windows 98 or older system.

I'd still use a batch file to do this, but only one, and here is why I'd use that batch file. You need something in between the Opus button and the external command line programs to parse the code. To manipulate it into what you want it to be as you're running into the unavoidable roadblock of how Windows parses double quotes.

So starting with the following example button code to launch one universal batch file:

<?xml version="1.0"?> {441626D7-0C39-4E9D-9631-F21D731B0C2A} Test.bat Test C:\WINNT\System32\shell32.dll,71 D:\Mine\cmd\Test.bat "{dlgstring|Enter Parameters|c:\temp ''}" {f}

Notice it is set to run as an MSDOS batch function. That is so only one program will be launched in the event you happen to have more than one program selected.

Notice I used {f} instead of your original {f!}, that is to prevent anything from happening should you push the button when nothing is selected.

Notice I enclosed the arguments within double quotes. That is necessary to keep the arguments together.

Notice the arguments come before the selected program. That is because Opus processes the dialog box before it does anything else.

Also notice in the button dialog box parameters, I used single quotes (C:\temp '') instead of double quotes (C:\temp ""). Why? To get around the way Windows parses double quotes. By initially substituting single quotes for double ones. The trick is once you have your arguments in the batch file, to replace the single quotes with double ones before passing the arguments on to your external command line programs.

Now below is the D:\Mine\cmd\Test.bat batch file:

@echo off
rem Get Entered Arguments less double quotes
set ARG=%~1

rem replace any single quotes with double quotes
set ARG=%ARG:'="%

shift
echo The arguments are: %ARG%
echo:
echo The program is: %1

pause

@Tanis:

You should have just called me an idiot. :smiley: I finally figured out why doptest wasn't running right for me. I had the button as "Run a program" rather than "Run an Opus function." I finally did get it to work. Sorry about that, and thanks. :blush: That doptest program is going to come in very handy in the future.

Using the information I recieved from doptest, I took the whole command line into a command prompt and found, like Nudel and JohnZeman said, that cmd.exe was the culprit in the way that it parsed the double quotes.

@Nudel:

Your solution works beautifully. Thanks for the thought you put into it.

@JohnZeman

I'm battling the clock this morning, so I don't have time to muddle through your post. I did make the batch file you suggested and ran it a few times, and the results are quite interesting. I'll be giving your post and your thoughts more time in the next day or two. Thanks for battling illness just to accomodate my laziness and stubbornness.

--chriscrutch

Oh wow my head was out of it more than I realized when I posted in this thread last time as I didn't even catch Leo's solution. That head cold flat knocked me out of commission a few days, I don't come down with a bug often but when I do it's usually a doozy like it was this time.