Hi DM,
Background: My login matrix has a feature where it can convert a .jpg etc. to a sixel using ImageMagick's conversion program. On Windows, it's very possible that the program may be installed in a directory with a space (i.e., somewhere in C:\Program Files). I was using a Windows test setup and making an update to my login matrix to try to allow running that with system.exec() by putting the fully-pathed executable in double-quotes. I did some debugging, adding " & pause" to the command so I could see the command window, and it complained about "C:\Program" not existing - Even though I put double-quotes around the fully-pathed executable, it seemed to be acting like those double-quotes were removed. I logged the command and verified the double-quotes were there.
I'm wondering if system.exec() removes double-quotes from the command it's given?
I'm also wondering if the same thing would happen on Linux (I haven't tested that).
I thought of one solution, to write the command to a batch file or shell script and run that (in a directory that doesn't contain a space), but I'm wondering if I could avoid that.
No, the double-quotes won't be removed. system.exec() is just a very-thing wrapper around system(): https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/system-w syste m?view=msvc-170
I'm also wondering if the same thing would happen on Linux (I haven't
tested that).
Nope, shouldn't.
https://www.man7.org/linux/man-pages/man3/system.3.html
Did you escape the double-quotes in the JS string passed to system.exec()? I think there's something else at play here.
No, the double-quotes won't be removed. system.exec() is just a very-thing wrapper around system():
Did you escape the double-quotes in the JS string passed to system.exec()? I think there's something else at play here.
Re: system.exec() and commands in double-quotes
By: Digital Man to Nightfox on Tue Apr 08 2025 09:54 pm
No, the double-quotes won't be removed. system.exec() is just a very-thing wrapper around system():
Did you escape the double-quotes in the JS string passed to system.exec()? I think there's something else at play here.
I did a bit more investigation. Since you say system.exec() is a wrapper around system(), I'm wondering if there may be a bug in system().
It seems that the issue happens when there are multiple things in double-quotes. I tried having it only run the converter program (so, the whole command was the fully-pathed executable in double-quotes), and that ran successfully.
In the command line I was trying to use, I have multiple things in double-quotes: The fully-pathed executable is first, then possibly some command-line parameters, and a source filename and an output filename. The fully-pathed executable, source filename, and output filename are all within their own set of double-quotes (in case there are spaces in their paths), and it seems that's when this issue happens where the Windows command interpreter only seems to be seeing "C:\Program" as the executable and fails due to that - even though the executable filename is in double-quotes.
If I remove the double-quotes around the source filename & destination filename, so that there's only one set of double-quotes in the command line (around the executable), then it succeeds.
If I remove the double-quotes around the source filename & destination filename, so that there's only one set of double-quotes in the command line
If I remove the double-quotes around the source filename & destination
filename, so that there's only one set of double-quotes in the command line
What if you do something silly and put the whole thing in one set of quotes, then escape the quotes inside?
If I remove the double-quotes around the source filename & destination
filename, so that there's only one set of double-quotes in the command line
What if you do something silly and put the whole thing in one set of quotes, then escape the quotes inside?
Re: system.exec() and commands in double-quotes
By: phigan to Nightfox on Thu Apr 10 2025 05:34 am
If I remove the double-quotes around the source filename & destination
filename, so that there's only one set of double-quotes in the command line
What if you do something silly and put the whole thing in one set of quotes, then escape the quotes inside?
That seems to work.. Thanks for the suggestion. And it seems to only be necessary on Windows.
lineIf I remove the double-quotes around the source filename & destination
filename, so that there's only one set of double-quotes in the command
What if you do something silly and put the whole thing in one set of
quotes, then escape the quotes inside?
That seems to work.. Thanks for the suggestion. And it seems to only be
necessary on Windows.
Maybe share the code?
Re: system.exec() and commands in double-quotes
By: Digital Man to Nightfox on Thu Apr 10 2025 03:47 pm
lineIf I remove the double-quotes around the source filename & destination
filename, so that there's only one set of double-quotes in the command
What if you do something silly and put the whole thing in one set of
quotes, then escape the quotes inside?
That seems to work.. Thanks for the suggestion. And it seems to only be
necessary on Windows.
Maybe share the code?
It's failry simple, basically just adding double-quotes around the whole command if you know the command has multiple sets of double-quotes.
I pasted the section of code on Pastebin:
https://pastebin.com/pPXfHKeP
Okay, so no "escaped quotes" are actually being passed to system(). I was confused by your reply to phigan.
The end result (passed to system()) looks like it would be:
""C:\Program Files\Path\To\Program" some-arg "some-arg""
That's pretty weird.
One nice thing about JavaScript is you don't have to escape the double-quotes if you inclose the string in single-quotes. So could probably get away without escaping anything.
Re: system.exec() and commands in double-quotes
By: Digital Man to Nightfox on Thu Apr 10 2025 05:14 pm
Okay, so no "escaped quotes" are actually being passed to system(). I was confused by your reply to phigan.
Maybe I'm not understanding what you mean by escaped quotes.. I escaped the double-quotes in the string with the command because I used double-quotes for the whole thing.
The end result (passed to system()) looks like it would be:
""C:\Program Files\Path\To\Program" some-arg "some-arg""
That's pretty weird.
Yeah, it's weird but it looks like that's what's working on Windows.
One nice thing about JavaScript is you don't have to escape the double-quotes if you inclose the string in single-quotes. So could probably get away without escaping anything.
I sometimes forget you can use single-quotes for strings in JS.
That seems to work.. Thanks for the suggestion. And it see
to only be necessary on Windows.
Sysop: | Rempala |
---|---|
Location: | Richlands, NC |
Users: | 113 |
Nodes: | 10 (0 / 10) |
Uptime: | 236:43:44 |
Calls: | 370 |
Files: | 6 |
Messages: | 111,346 |