English 中文(简体)
powershell bash loops are randomly stuck waiting for keyboard input
原标题:

I have bash script I am running from powershell in windows that does a for loop. Every once in a while, one of the loop iteration hangs until I hit enter on the keyboard.
This doesn t happen all the time, in fact, it happens pretty rarely, but it still does.

The interesting thing is that my loop innards is basically time _command_ and so after I hit enter, it ll tell me how long the command took to run. The command actually takes way less time to execute than the loop iteration takes - because it s waiting for keyboard input for some odd reason.

It s pretty annoying to leave a script running overnight and come back in the morning to see that it didn t get very far.

Does someone knows WHY this happens and WHAT to do to get around it?

Thanks, jbu

问题回答

I have encountered the same problem several times. Now I guess I have found the reason!

If you ever press the mouse within the powershell, it might get stuck and need user to press "enter" to continue. So the get-around-way is to make sure that you didn t accidentally press your mouse within the shell window while you are already running some program...

Goto the powershell properties and unselect Quick Edit / Insert check boxes. If these are selected, the console pauses output and resumes only when an Enter key is pressed ( You can identify this by monitoring the console title bar- it will switch from "Administrator:Windows PowerShell" to "Select Administrator:Windows Powershell"

Until you post the script, there s little we can do to help.

However, in general, one of your commands probably returns a null once in a while as input to stdin of another command which, upon seeing null looks to the terminal as stdin. Or something along those lines.





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签