I want run ncftpput in go and want to get the output string for analysis but Only the following style can be output.
cmdStr := "ncftpput -R -f C:\\Users\\xx\\source\\go\\depolyment\\cfg\\login.cfg / C:\\Users\\xx\\source\\go\\depolyment\\cfg"
args := strings.Split(cmdStr, " ")
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
I have tried many methods and the output is allways empty,such as:
cmd.Output()
cmd.CombinOutput()
io.Pipe()
Who can help me solve this problem, tks!
From the man page of ncftpput :
Like many commands (
greporlswith their colored output for example), ncftpput tries to detect if it is running in a terminal or not, and changes its default output based on that.In a shell : try running
ncftpput ... > /tmp/output && cat /tmp/outputorncftpput ... | catto see what's the output when stdout is not a terminal (spoiler: it is probably going to be empty).A command run in a
exec.Commandcontext is not run in a terminal context (its output is not a tty).In your particular use case with
ncftpoutput, if you want your progress meter output in all circumstances : just add-vto your command.