Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've been searching on the internet but I did not find the right answer, so, my question is, how can I run a Go program during 5 minutes and after this 5 minutes exit the script?
Add this line of code to the beginning of the main() function:
time.AfterFunc(5*time.Minute, func() { os.Exit(0) })
This causes os.Exit(0) to be called after 5 minutes.
Here it is on the Go playground (minutes convert to seconds for example): https://play.golang.org/p/wybKWM2BEep
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a character device /dev/abc. I have to perform the read write operation to this character device from a shell script. how can I do it?
To read from the character device:
dd if=/dev/abc
To write to the character device:
echo "text" > /dev/abc
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Iam writing go and I am having 300 go routines running at the same time.
When one of them crashes the print log becomes incredibly long and I endup scrolling up every time (I only need to see the last line of my log and the first go routine failing).
How are you making your developer experience nicer in go?
You can pipe the output of your program to a file
./program 2>&1 > log.txt
or to a program that lets you view the buffer head first
./program 2>&1 | less
The 2>&1 part combines stdout and stderr, so you get regular program output and error messages in the same buffer.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am looking for a way to stop the current running script and restart it if a continuation is met.
How can I do that?
Write like this:
at_exit{
# whatever way you started the program originally such as `program_name`.
# Make sure that the new process is detached from the original.
}
and then do:
exit
somewhere where you want to break.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm in the process of writing a program that will open a .txt file, and allow the user to edit the file, then save it. I'm not really sure how to go about writing a func that opens a text editor(TextEdit, Cat, VIM, w/e) halfway through the program, waits for a user to make changes to that file, then continues running once those changes are complete. Is go capable of doing this? Any suggestions/examples would be appreciated.
This really doesn't have anything to do with go specifically, you start the process, wait for it to exit and then do your thing:
cmd := exec.Command("vim", "file.txt")
if cmd.Run() != nil {
//vim didn't exit with status code 0
} else {
//it worked, do stuff with file.txt
}
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
when I debug,I clean the log info frequently.
Is there any hotkey for that
If you mean the console window, its clover-K: ⌘-K I think.
Yes there is, it is:
⌃+⌥+⌘+R
Soure: http://www.1729.us/xcode/Xcode%20Shortcuts.pdf
control + option + command + R
You can use the above.