go - golang failed exec command that works in terminal -


i getting error when try use exec package run mv command.

here example of trying do:

cmd := exec.command("mv", "./source-dir/*", "./dest-dir") output, err := cmd.combinedoutput()  cmd.run() 

err returns following exit status 1

output returns mv: rename ./source-dir/* ./dest-dir/*: no such file or directory

i can script work when change line:

cmd := exec.command("mv", "./source-dir/*", "./dest-dir")

to following:

cmd := exec.command("mv", "./source-dir/file.txt", "./dest-dir")

the command works , moves file using wildcard doesn't work. appears asterisk isn't being used wildcard in command. why that? there way use wildcards in go? if not how else able recursively move files source-dir dest-dir?

thanks

when type command @ shell, shell takes ./source_dir/* , replaces list of of files match, 1 per argument. mv command sees list of filenames, not wildcard.

what need either same thing (using filepath.glob returns []string of matching files), or invoke shell can work (using exec.command("/bin/sh", "-c", "mv ./source_dir/* ./dest_dir")).


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -