Command line passing quotes within quotes
Asked Answered
P

3

16

I've been searching for a solution to this but couldn't find one. Not sure if its possible.

Can I pass into command-line execution that passes a in a bat file which has an input file as its arguments?

So from the command-line it'll look like this:

C:\run.exe "C:\space folder\run.bat "C:\space folder\input.txt""

The problem is with the folders that has spaces so the quotes are required to be in there.

Pentahedron answered 10/12, 2013 at 1:37 Comment(0)
D
15

Try this:

C:\run.exe "C:\space folder\run.bat \"C:\space folder\input.txt\""

And here is a link that you can see all escape characters http://www.robvanderwoude.com/escapechars.php

Dickie answered 10/12, 2013 at 1:41 Comment(6)
I thought about that, but wouldn't it err on the last address location, I.e. it would attempt to view input.txt/ as a folder?Ampliate
No, It parses all line before execute.Dickie
Ahh. Can't one also use UNIX styled directory syntax on windows? E.g. C:/space\ folder/run.bat?Ampliate
Yeah, acn, but some batch commands could not execute with this syntaxe. I've had running on issues on this paste time, but I don't remeber right now.Dickie
I see. +1 by the way for reference.Ampliate
I tried running that and in my run.exe i just call "echo %1" to see if the whole string got parsed. But i got this in return: "C:\space folder\run.bat \"C:\space It cuts off in the space from the input.txt directoryPentahedron
L
2

I know it's an old topic, but I found the answer and would like to share.

In Windows you don't have to escape the quotes. Just use them normally.

In this case:

C:\run.exe ""C:\space folder\run.bat" "C:\space folder\input.txt""

Loiret answered 4/3, 2016 at 14:3 Comment(3)
Are you sure? I made a simple run.bat file with two lines "echo %1" and "echo %2". Then I passed in your suggested string as argument. The first parameter %1 was shown to be ""C:\space and the second was shown to be folder\run.bat" "C:\spaceCalfee
echo may be a special case since it's not really disk-based command, but a built-in one. It may just output everything after it.Falsify
The problem is that there are two different ways to receive command lines, GetCommandLine() or main(int, char**). echo "Hello" prints quotes while the same received as args[] has no quotes.Widdershins
S
1

In the end, all I needed was quotes.

winrs -r:MACHINE001 ""C:\Program Files\MyApp\My App.exe" -x "LOTS OF PARAMETERS""
Somber answered 27/10, 2022 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.