Run Command without Single Quote

#1

Windows:
I want Julia to run a command to 7-zip a file, i.e. following works in my terminal:

7z a c:\test\f1.zip c:\test\f1.txt

I have to use Double Quote or No Quote for the file name, otherwise, If I use Single Quote, 7 zip Output an Error

However, when I do this in Julia,

cc = `7z a c:\\test\\f1.zip c:\\test\\f1.txt`

run(cc)

This failed, because when I do
println(cc)

It generate this output:

7z a 'c:\test\f1.zip' 'c:\test\f1.txt'

How come Julia added single quote around file name? I dont like it because it will break my 7-zip command. 7z only accept double quote or No quote.

Thank you

0 Likes

#2

Have you tried it without the double quotes and using backslashes to escape the spaces?

0 Likes

#3

I changed my example, it still does not work…

0 Likes

#4

I’m pretty sure that’s just a printing thing (the single quotes). That command works fine for me:

julia> cmd = `7z a E:\\Downloads\\foo.zip E:\\Downloads\\foo`
`7z a 'E:\Downloads\foo.zip' 'E:\Downloads\foo'`

julia> run(cmd)

7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

Open archive: E:\Downloads\foo.zip
--
Path = E:\Downloads\foo.zip
Type = zip
Physical Size = 2412099
Comment = e16eaa0b8d8ccf3f432c9ef46cbbc6453789fce7

Scanning the drive:
1 folder, 0 files, 0 bytes

Updating archive: E:\Downloads\foo.zip

Items to compress: 1


Files read from disk: 0
Archive size: 2412099 bytes (2356 KiB)
Everything is Ok
Process(`7z a 'E:\Downloads\foo.zip' 'E:\Downloads\foo'`, ProcessExited(0))
0 Likes

#5

I am using Windows 10 Enterprise + Julia 1.1 + 7-zip (2019-02-21) 64 bits

cc = `7z a c:\\temp\\f1.zip c:\\temp\\f1.txt`
run(cc)

IOError: could not spawn 7z a 'c:\temp\f1.zip' 'c:\temp\f1.txt': no such file or directory (ENOENT)
_spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at process.jl:400
setup_stdios(::getfield(Base, Symbol("##505#506")){Cmd}, ::Array{Any,1}) at process.jl:413
_spawn at process.jl:412 [inlined]
#run#515(::Bool, ::Function, ::Cmd) at process.jl:725
run(::Cmd) at process.jl:724
top-level scope at none:0

Then I open a windows terminal
Without Single Quote, it works:
7z_1

Adding Single Quote, it failed, exactly the same as Julia 's case

@pfitzseb Could you try this:

  1. In a windows command line, you try to add Single Quote to your file name, does it still work?
    i.e. you will run this in windows command line, not Julia REPL:

7z a 'E:\\Downloads\\foo.zip' 'E:\\Downloads\\foo'

  1. If you upgrade you 7 zip to v19 or latest 2019-02 version, with 64-bit, does it still work?

Thank you

0 Likes

#6

Those are different errors. I’m pretty sure Julia can’t find 7z for some reason, so try specifying the complete path (e.g. as joinpath(Sys.BINDIR, "7z") if you want to use the 7zip shipped with Julia).

0 Likes

#7

Isn’t the latest problem that you have c: instead of C:?

0 Likes