I want to run exiv2
from Julia, but the command I need has very weird syntax: exiv2 -M"set ..."
. Julia transforms this to exiv2 '-M"set ..."'
, which fails to run.
Is there a way to force Julia not to quote those quotation marks?
raw string literal?
Nope -- still inserts the '
.
julia> rsl = r"""-M"set ..." """
r"-M\"set ...\" "
julia> cmd = `exiv2 $rsl`
`exiv2 'r"-M\"set ...\" "'`
You can use single quotes if there is nothing for the shell to interpolate
You could also check how Julia itself parses its own flags, since it has julia -C"native,..."
Single quotes don't work here; if I use them, Julia inserts double quotes. I'm not sure seeing how Julia parses those is useful here, since the problem is declaring the command, not parsing it.
I see. My only thought is to construct a valid command in your shell, write the string to a file, and inspect the bytes to reproduce it in Julia.
with a hex editor
That's a good idea, thanks!
But I wonder if I'm missing something, or if this is a limitation of Julia's command declaration syntax and opening an issue is warranted.
No idea how useful that would be, but it may at least give you an idea of where the bytes differ and give some insight on how to correct them
Which OS are you on?
Linux.
Best I could come up with as a newbie:
run(setenv(`sh -c "echo \$TEST"`, ("TEST" => "exiv2 -M\"set foo\"",)));
that will at least echo what you want using a shell subprocess
No idea how to remove the envar
Thanks for giving it a shot!
Hm, exiv2
is not doing what it's supposed to do when I run it like this. Everything looks fine, though.
Anyway, I found a workaround (I can write the command to a temporary file and point exiv2
to it). I think I'll open an issue, though; Julia should be able to handle this syntax.
I see your frustration
Cmd(["exiv2 -M\"set Xmp.dc.title lang=en-US Hello\" /home/mfiano/Temp/test.png"])
I mean those damn single quotes
I just spent a half hour trying to figure it out. It seems Julia is trying to be too clever with its interpolation. Inserting a backslash to escape a double quote automatically places the whole string in single quotes, which is not a valid command.
Yep, that's it.
Please file an issue!
FWIW, in this specific case you can also call exiv2
with
julia> run(`exiv2 "-Mset Exif.Photo.UserComment My Photo 333" transport.png`)
Process(`exiv2 '-Mset Exif.Photo.UserComment My Photo 333' transport.png`, ProcessExited(0))
shell> exiv2 transport.png
...
Exif comment : My Photo 333
actually, what's the command that's failing for you?
julia> run(`exiv2 -M"set Exif.Photo.UserComment My Photo3" transport.png`)
Process(`exiv2 '-Mset Exif.Photo.UserComment My Photo3' transport.png`, ProcessExited(0))
also works fine for me
I think I was confused by Julia eliding the "
s:
julia> `exiv2 -M"set Exif.Photo.UserComment My Photo3" image.jpg`
`exiv2 '-Mset Exif.Photo.UserComment My Photo3' image.jpg`
I assumed this would fail. So I tried this:
julia> run(`exiv2 -M\"set Exif.Photo.UserComment My Photo3\" image.jpg`)
-M option 1: Invalid command line:
exiv2: Error parsing -M option arguments
Usage: exiv2 [ options ] [ action ] file ...
Manipulate the Exif metadata of images.
ERROR: failed process: Process(`exiv2 '-M"set' Exif.Photo.UserComment My 'Photo3"' image.jpg`, ProcessExited(1)) [1]
and I think from here I went down a rabbit hole instead of just doing the simplest thing, running the original command :sweat_smile:
yeah, Cmd printing is very confusing
Julia tries to be too smart for its own good
mbaz has marked this topic as resolved.
Last updated: Dec 28 2024 at 04:38 UTC