Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I check the progress of a script.Exec() command? #176

Open
aaronpkelly opened this issue May 20, 2023 · 2 comments
Open

How can I check the progress of a script.Exec() command? #176

aaronpkelly opened this issue May 20, 2023 · 2 comments

Comments

@aaronpkelly
Copy link

I have a long running Exec() query:

script.Exec("/home/aaron/big-script.sh")

This command takes a long time, but is always successful.

How can I check the progress of this Exec query? How do I know if it's still in-progress, or has finished running it's command?

I don't think I can check the exit status of the Pipe (as far as I can see), because that will only be set if there's an error

@bitfield
Copy link
Owner

You can use Wait to wait for the pipe to finish:

script.Exec("/home/aaron/big-script.sh").Wait()

Alternatively, if the script produces output, you can copy it to the terminal while waiting:

script.Exec("/home/aaron/big-script.sh").Stdout()

@rmasci
Copy link

rmasci commented Aug 4, 2023

One of the things I like to do when waiting for a long time is let the users know. -- hey it's gonna take a few. then I give it a spinner. This gives the impression that the computer or process didn't lockup -- that it's working on it. There are many different spinner functions, but test first not all of them work well with the user's terminal such as putty.

quit:=make(chan bool)
fmt.Println("going to run big-script.sh This is going to take a while.")
go spinner(quit)
script.Exec("big-script.sh").Stdout()
quit <- true

Spinner Function:

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/artyom/spinner"
)

func spin(quit chan bool) {
	fmt.Println("")
	spnr := spinner.New(os.Stdout, "  Working: ")
	for {
		select {
		case <-quit:
			spnr.Clear()
			return
		default:
			spnr.Spin()
		}
		time.Sleep(250 * time.Millisecond)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants