cd into before exec
benjamin79 opened this issue · 4 comments
Hi,
thanks for the lib. I need to use zip. But it doesn´t allow to set a specific directory for zipping. How can i set a dynamic root folder from which the command gets executed?
Porcelain.exec("zip", [document.name,* ] )
The contents are in random folders like 3635433.
@benjamin79 Available options are described in the docs, see https://hexdocs.pm/porcelain/Porcelain.html#exec/3.
You need the :dir
options:
Porcelain.exec("zip", [document.name,*], dir: <your path here>)
Thank you for your fast answer.
At the command line (ubuntu 16.04) i can do
zip -r files.zip *
and it works.
Perhaps i´m doing something wrong, but the following leads to an error in zip
Porcelain.exec("zip", ["-r","files.zip","*" ], dir: "/tmp/123/" )
-> out: "\tzip warning: name not matched: *\n\nzip error: Nothing to do!
If i use System.tmp_dir()<>"/"<>random<>"/"
instead of "*"
the zipping works, but i get the parent folders like tmp ... 657890 in the zip file.
Got it: Works with using .
instead of *
. But i don´t know why.
@benjamin79 *
is a wildcard that is expanded by the shell when you execute the command there. Porcelain.exec
does not perform any argument expansion, it passes them as is to the invoked command.
If all you want is archive the current directory, your solution with .
is fine.
Porcelain also has shell()
which invokes a shell and passes the command string to it, simulating the behaviour you get by executing the command directly in a shell. You can use it as follows:
Porcelain.shell("zip -r files.zip *", dir: "/tmp/123/")