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.
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 7 years ago.
Improve this question
Let's say as an example that I wanted to write a script file that not only kept count of how many times it's been called, but would average the time that it has been called since the first time. and to do this without relying on environmental variables or secondary files. And report the number of lapsed days as well. This would mean that it would have to be self-modifying. Now when a script is loaded and executed, the saved version on disk can be changed without effecting the copy in memory, so that works, or should. Just change the copy on file.
But making it happen can be a bit tricky. So what is your best solution?
Sounds a bit weird, but a bash script is just text, so you can always edit it IF you have permission:
Take this example:
#!/bin/bash
VAR=1
let VAR=VAR+1
echo Set to $VAR
perl -pi -e 's/^VAR=\d+/VAR='$VAR'/' $0
Trying it out:
$ /tmp/foo.sh
Set to 9
$ /tmp/foo.sh
Set to 10
$ /tmp/foo.sh
Set to 11
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
I often need to move file from one location to other, but it requires copying and pasting huge part of the command. For example:
mv ~/Projects/foo/bar/baz.img ~/Projects/foo/bar/fiz.dmg
Is it possible after entering ~/Projects/foo/bar/baz.iso part of above command to use some shortcut that duplicates it so I can change the very end to fiz.dmg?
You don’t need this:
mv ~/Projects/foo/bar/baz.img ~/Projects/foo/bar/fiz.dmg
easily turns into
mv ~/Projects/foo/bar/{baz,fiz}.img
. Note: zsh completion is still available when you write { (unless you have a habit of writing closing } right away) if you want it.
I actually discovered one possible solution. Just press:
Ctrl+W few times and then Ctrl+Y two times (and space between pastes).
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
I'm very new to shell scripting. I have a basic doubt of what is the use of & in shell scripting? That is doing something like this :
commands arg &
Waits to give more input. But what is its exact use? How should I use it in real world?
As you have used it there, it runs commands arg in the background, disconnected from your keyboard, and the shell immediately asks you for its next command.
As for the real world, I use it when I have a command that will take some significant time to run but does not require any input from me and will put all of its output into a file, for example
# walk through the whole filesystem looking for a particular filename
find / -name 'obscure.filename' -print > /tmp/found-it &
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
How to exit from the long output of a terminal command or a git command like git log or git branch -a?
How to avoid that I have to press enter untill the output of the command is complete?
git log uses more or less for paging the output.
You can press q to stop more/less and drop the remaining output.
Ctrl-C is the entire answer, though it's too short to go in this field.