Re: [go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread Dean Schulze
The variadic args worked perfectly.  Thanks.

I did not use the archive/tar and compress/gzip approach because that wold 
be a lot more complicated than just executing a tar command.  Those 
packages are oriented towards reading/writing the contents of 
archive/compressed files into the program rather than just extracting a 
file from a compressed archive.

On Wednesday, April 20, 2022 at 10:28:06 AM UTC-6 wagner riffel wrote:

> On Wed Apr 20, 2022 at 6:16 PM CEST, Dean Schulze wrote:
> > I need to execute this tar command
> >
> > *tar xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/*
> >
>
> Did you considered using the packages "archive/tar" and
> "compress/gzip" to achive this?
>
> > *argStr := "xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/"output, err
> > := exec.Command("tar", argStr).Output()*
> >
>
> exec.Command arguments are variadic, each argument is one argv, thus I
> think you meant exec.Command("tar", "xzf", "dir1/dir2/somefile.tgz",
> "--directory=dir1/dir2/")
>
> -w
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2556c040-94e3-487e-b5b1-ecbe75bb7d47n%40googlegroups.com.


Re: [go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread 'Axel Wagner' via golang-nuts
On Wed, Apr 20, 2022 at 6:16 PM Dean Schulze 
wrote:

> I need to execute this tar command
>
> *tar xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/*
>
> from within a Go program.  I've verified that it works from the command
> line.  I've tried using
>
>
> *argStr := "xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/"output, err
> := exec.Command("tar", argStr).Output()*
>

You need to pass the args separately, not as one string:
output, err := exec.Command("tar", "xzf", "dir1/dir2/somefile.tgz",
"--directory=dir1/dir2/").Output()
I also tend to set `cmd.Stderr = os.Stderr` to make sure I see error
messages, when executing commands.


>
>
> but it returns an error code of 2 with no other output indicating what is
> wrong.
>
> Using exec.Command(name, arg) is always a guessing game as to what the
> command name should be and what the argument should be.  How do I execute
> this tar command from within Go?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/4c4345b7-2155-4bd9-ba61-7a76b5256d2fn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfFC_oZz%2BWxu7b4wuaY0GqchK5wUaLVu6AhQ708OmCjOtw%40mail.gmail.com.


Re: [go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread 'wagner riffel' via golang-nuts
Also, the Output method only returns what was wrote to stdout, tar
argument parsing errors are probably in stderr, using CombinedOutput()
has better effect to debug.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CJF7P5OFW5I8.2YK5VGDWTSBVV%40pampas.


Re: [go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread 'wagner riffel' via golang-nuts
On Wed Apr 20, 2022 at 6:16 PM CEST, Dean Schulze wrote:
> I need to execute this tar command
>
> *tar xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/*
>

Did you considered using the packages "archive/tar" and
"compress/gzip" to achive this?

> *argStr := "xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/"output, err
> := exec.Command("tar", argStr).Output()*
>

exec.Command arguments are variadic, each argument is one argv, thus I
think you meant exec.Command("tar", "xzf", "dir1/dir2/somefile.tgz",
"--directory=dir1/dir2/")

-w

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CJF7II5MD0Y9.2Y2HYXCZ4QDSC%40pampas.


[go-nuts] Executing a tar command from within a Go program

2022-04-20 Thread Dean Schulze
I need to execute this tar command 

*tar xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/*

from within a Go program.  I've verified that it works from the command 
line.  I've tried using 


*argStr := "xzf dir1/dir2/somefile.tgz --directory=dir1/dir2/"output, err 
:= exec.Command("tar", argStr).Output()*

but it returns an error code of 2 with no other output indicating what is 
wrong.

Using exec.Command(name, arg) is always a guessing game as to what the 
command name should be and what the argument should be.  How do I execute 
this tar command from within Go?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4c4345b7-2155-4bd9-ba61-7a76b5256d2fn%40googlegroups.com.