简体   繁体   中英

bash script on cygwin - seems to get stuck between consecutive commands.

I am using a bash script to run a number of application (some repeatedly) on a Windows machine through cygwin. The script contains commands to launch those applications, line by line. Most of these applications run for many minutes and many times I have observed that the i+1 th application is not being started even after i th application is completed. In such cases, if I press enter in the cygwin console on which the bash script is running, the next application starts running. Is it because of any issue with bash on cygwin? Or is it an issue with the Windows OS itself? Have any of you observed such an issue with bash + cygwin + Windows?

Thanks.

I think I have seen this before.

Instead of

somecommand

try

somecommand </dev/null

If that doesn't work, try

cmd /c somecommand

Or experiment with other redirections, eg

somecommand >/dev/null

Sounds like you may have a problem with your shell script encoding; DOS (and Windows) uses CR + LF line endings, whereas Linux uses LF endings. Try saving the file as LF .

What might also be going on:

When I was running Cygwin on a school laptop, I encountered a dramatic slowing of shell scripts vs. when they were running in a native Linux environment. This was especially apparent when running a configure script from GNU Autotools.

  • Check your path for slow drives. (From the Cygwin FAQ ):

Why is Cygwin suddenly so slow?

If suddenly every command takes a very long time, then something is probably attempting to access a network share. You may have the obsolete //c notation in your PATH or startup files. Using //c means to contact the network server c, which will slow things down tremendously if it does not exist.

  • You might also want to check whether you have an antivirus program running. Antivirus programs tend to scan every single executable file as it is executed; this can cause problems for even simple shell scripts that run hundreds or even thousands of individual programs before they run their course.

  • This mailing list post outlines what is needed to pseudo-mount the main /usr/bin directory as cygexec . I'm not sure what that does, but I found it helped.

  • If you're running a configure script, try the -C option.

Hope this helps!

Occasionally, I'll get this behaviour because I have accidentally deleted the 'she-bang' at the top of the script, that is, deleted the #!/bin/bash on the first line of the script.

It's even more likely for this to happen when a parent shell script calls a child script that has the she-bang missing!

Hope this helps.

A bit of a long shot, but I have seen some similar behaviour previously.

In Windows 2000, if any program running in a command prompt window had some of it's text highlighted by the cursor, it would pause the command running, and you had to press enter or clear the highlighting to get the command prompt to continue executing.

As I said, bit of a long shot, but accidental mouse clicks could be your issue...

Install cygwin with unix style line breaks and forget weird problems like that.

Try saving your script as "the-properly-line-broken-style" for your cygwin. That is, use the style you specified under installation.

Here is some relevant information:

https://stackoverflow.com/a/7048200/657703

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM