send string to Command Prompt window with embeded quotes

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
gpapp
Newbie
Posts: 16
Joined: Tue Dec 21, 2004 8:00 pm

send string to Command Prompt window with embeded quotes

Post by gpapp » Wed Sep 15, 2010 2:03 pm

My string looks something like this:

runprog.exe –a –f “C:\My Folder\filename.txtâ€

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Sep 15, 2010 2:20 pm

If I do:

Let>text=runprog.exe –a –f “C:\My Folder\filename.txtâ€

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Sep 15, 2010 2:26 pm

I understand the issue.

The issue is in passing a parameter to a compiled exe.

The CMD shell is designed to strip double quotes.

So do this:

C:\>mytest /mystring="'hello there'"


Put the string/path/whatever inside of single quotes, and wrapped with double quotes on the outside.

Then inside the Macro Scheduler program do a replace on single quotes and change to double quotes.

gpapp
Newbie
Posts: 16
Joined: Tue Dec 21, 2004 8:00 pm

Post by gpapp » Wed Sep 15, 2010 2:33 pm

Thanks regarding the insight of the CMD shell.
The use of single quotes to get past the interface limitations is clever.
Just looking at it I'm sure this will work.
I'll test it out as soon as possible.
gpapp

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Sep 15, 2010 2:44 pm

Another method is to "URL Encode" the string
and then unencode the string inside Macro Scheduler.


Like this:

Code: Select all

VBStart
VBEnd
VBEval>unescape("%mystring%"),mystring
MessageModal>mystring

And then the command line would be passed like this
C:\>mytest /MYSTRING=%22hello%20there%22

gpapp
Newbie
Posts: 16
Joined: Tue Dec 21, 2004 8:00 pm

Post by gpapp » Thu Sep 16, 2010 5:57 pm

Thanks to adroege for a very good suggestion.

In my application I need to send text to the Console window that has very long and complex strings. These contain embedded spaces and also embedded double quotes.

I made the adroedge example into a full macro then complied it into MyCommand.EXE.

Here is a possible usage in VisualBasic, this in a loop.

dim instring , outstring, commandstring as string
commandstring = "C:\Test Files\My Run.BAT"

instring = "testprog.exe -f=""" & commandstring & """"
outstring = urlencode(instring)
call waitforshell("C:\MyCommand.exe /mystring=" & outstring,1)

testprog.exe is any EXE or BAT program that can run in the Command shell, and requires command-line arguments

note the triple quotes for instring, this is one way to embed double quotes inside a string in VBA. In my code, the value of commandstring changes.

/mystring= is the way to pass the encoded string through to MacroScheduler as argument named "mystring"

urlencode and waitforshell can be found on the web.
gpapp

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts