Re: system.exec() and commands in double-quotes
By: Nightfox to Digital Man on Tue Apr 08 2025 08:52 pm
> 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?
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-wsystem?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
> 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.
Did you escape the double-quotes in the JS string passed to system.exec()? I think there's something else at play here.
--
digital man (rob)
Sling Blade quote #23:
Karl: I reckon I'm gonna have to get used to looking at pretty people.
Norco, CA WX: 63.0øF, 61.0% humidity, 0 mph N wind, 0.00 inches rain/24hrs
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net