Trouble with script quoting

Discuss and share scripts and script files...
Post Reply
RalphM
Posts: 1669
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Trouble with script quoting

Post by RalphM »

I'm trying to create a CFA to convert mp4 videos with ffmpeg and while I managed to make the conversion with the following command line:

Code: Select all

C:\Program Files\ffmpeg\bin>ffmpeg.exe -err_detect ignore_err -i D:\Temp\xxx.mp4 -c copy -an D:\Temp\yyy.mp4
I cannot get the CFA (and all its variations of quoting I tried so far) to work:

Code: Select all

|"Convert CCTV w/ ffmpeg" mp4>::foreach ($item, <pfaitems>) {run """C:\Program Files\ffmpeg\bin\ffmpeg.exe -err_detect ignore_err -i ""$item"" -c copy -an D:\Temp\yyy.mp4"""}
The "yyy.mp4" is static at the moment and would only work for one file right now but once the command works, I plan to dynamically adapt the name to "<base>_fix.mp4" for each file.
Naturally, both source and destination paths can contain spaces and the quoting above was copied from an Irfanview CFA that had trouble with such filenames.
Ralph :)
(OS: W11 21H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

highend
Posts: 11724
Joined: 06 Feb 2011 00:33

Re: Trouble with script quoting

Post by highend »

Code: Select all

|"Convert CCTV w/ ffmpeg" mp4>::foreach ($item, <pfaitems>) { $base = gpc($item, "base") . "_fix"; run """C:\Program Files\ffmpeg\bin\ffmpeg.exe"" -err_detect ignore_err -i ""$item"" -c copy -an ""D:\Temp\$base.mp4"""; }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

RalphM
Posts: 1669
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Trouble with script quoting

Post by RalphM »

Thanks highend for pointing me in the right direction. :appl:
Your version does exactly what I described, I extended it in the meantime to put the new file in the same directory as the source and to copy the timestamps from the source as well.

While I can see that I missed some "" in my version, I will probably end up struggling again in the future - all I've seen and read so far about quoting in XY scripts makes somewhat sense on paper but is just not logical to me.
Why do I need another "" after ffmpeg.exe? Why can't the options be included in that quoted string?
Ralph :)
(OS: W11 21H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

highend
Posts: 11724
Joined: 06 Feb 2011 00:33

Re: Trouble with script quoting

Post by highend »

Because outer quotes (of scopes) get stripped.

run """C:\Program Files\ffmpeg\bin\ffmpeg.exe"" -err_detect ignore_err -i ""$item"" -c copy -an ""D:\Temp\$base.mp4""";
->
run "C:\Program Files\ffmpeg\bin\ffmpeg.exe" -err_detect ignore_err -i "$item" -c copy -an "D:\Temp\$base.mp4";
which makes perfectly sense
Why can't the options be included in that quoted string?
You are free to use e.g. a heredoc to make quoting easier...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

WirlyWirly
Posts: 160
Joined: 21 Oct 2020 23:33
Location: Through the Looking-Glass

Re: Trouble with script quoting

Post by WirlyWirly »

I've been playing around with quotes for the last few hours hours but haven't made any progress.

Normally I use run lax("program.exe" -flag1 -flag2 <selitem>) and it works great. Quotes can't be used in filenames so I've never had issues.

However, now I'm trying to write a simple script that will take an input("Enter password"), which may contain any number of quotes.

This is the line I'm using in my popupnested() menu, the goal is to request a password and then mount the <selitem> through VeraCrypt. The command works fine if I use a password that contains no quotes, however I'd like to be able to use this script with any password.

Code: Select all

Mount: <curname>|$password = input("VeraCrypt: Mount the file '<curname>' as a volume", "Enter password");run lax("$PORTABLEAPPS\VeraCryptPortable\VeraCryptPortable.exe" /volume "<selitem>" /password ""$password"" /beep /explore /mountoption label="<curname>" /quit /silent)|
Failing Test Password (quotes): |'P=(^@Rhx6"%([3@Q9;,UUf"kZ-eV|HIFM~,0'@-F/bCm}ZJ#9b/.~08;7<

Succeeding Password (no quotes): $dtWZ0YJl-fl\$b|rB>?2dV\+Cv5=nr\7&iUdJNND7sD*8krDR{,^_>+KBA6


Any tips?

P.S
I'd like to hide the characters in the user-input box but it doesn't seem to be an option, is there a way to do this? What about changing the title of the window from input to a custom string? It'd be nice to have a unique window title that I could match with KeePass' auto-type feature.

highend
Posts: 11724
Joined: 06 Feb 2011 00:33

Re: Trouble with script quoting

Post by highend »

I'm afraid, no.

Even if a new scripting command would be introduced like
str(<some string>)
real(<some string>)

that could handle everything inside of it regardless if it contains an uneven number of single or double quotes...

Would run / runret handle that correctly (without too much effort)?

Regarding password hiding:
You could use a html dialog with <input type="password"> instead
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

WirlyWirly
Posts: 160
Joined: 21 Oct 2020 23:33
Location: Through the Looking-Glass

Re: Trouble with script quoting

Post by WirlyWirly »

After playing around with it some more, I still couldn't get it working. Tried both the html("<input>") and runret. No dice.

What I ended up doing was changing my password to not use quotes. Not my ideal solution, but it's a minor inconvenience.

However, I then stumbled upon a VeraCrypt flag /secureDesktop no that will display a minimal GUI window to enter a password. It includes a lot of what I was trying to do with my script (including a somewhat unique window title) so I'm going to scrap the input() dialog I was using. Thanks for trying to help though, appreciate it!

Image

highend
Posts: 11724
Joined: 06 Feb 2011 00:33

Re: Trouble with script quoting

Post by highend »

Code: Select all

    $html = <<<>>>
        <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
        </head>
        <title>Password input</title>
        <body>
            <form method="get" action="xys:">

                <label for="pass">Password 8 characters minimum</label>
                <input type="password" id="pass" name="password" required>

                <input type="submit" name="ok" value="Ok">
                <input type="submit" name="cancel" value="Cancel">
            </form>
        </body>
        </html>
    >>>;
    $htmlResult = html($html, 400, 565, self("base"));
    text $htmlResult;
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Post Reply