#How can I pipe terminal commands using WithExec function

1 messages · Page 1 of 1 (latest)

cunning hatch
#

I.e. the following sample does not work. It seems like the pipe char recognized as another argument

// find the biggest files in the directory recursively
func (m *Dagger) FindBiggestFiles(ctx context.Context, directoryArg *Directory) (string, error) {
return dag.Container().
From("alpine:latest").
WithMountedDirectory("/mnt", directoryArg).
WithWorkdir("/mnt").
WithExec([]string{"du", "-ah", ".", "|", "sort", "-rh", "|", "head", "-20"}).
Stdout(ctx)
}

#

Found my answer. Sharing here as well for other fellows WithExec([]string{"sh", "-c", "du -ah . | sort -rh | head -20"}). 🙌

sharp robin
#

Thanks! I ran into this with > just now.

#

Couldn't figure out why rm [file] would work, but echo > [file] would write nothing 🙂 Turns out it was interpreting > as just another thing to be echo'd.