Run "./" bash/batch file with cygwin - linux

Well the idea goes as followed,
I have a bash file for linux, there I obviously run it by making ./my_run.
The problem is I'm in windows so I downloaded and installed cygwin.
I added cygwin bin to the Enviromental Variables and check that at least "ls" works so I guessed I did it well.
When I try to run it with the cmd it displays:
'.' is not recognized as an internal or external command,
operable program or batch file.
As if the cygwin variables were not correctly installed (as I said I tried ls and works).
Then I tried it directly with cygwin and when doing the ./my_run I got it to work right.
So how is that I can use some commands like ls but when doing ./ it doesn't work on the cmd? How can I fix this?

Well, cygwin is only a shared library and a lot of stuff (the programs) using it (read Cygwin doc). cygwin.dll changes internally path resolution / chars to allow you to say ./my_script and converts it to .\my_script before doing the actual windows call, it also adds the proper extension to executables to allow it to execute windows binaries. This magic persists as long as you use it. cmd.exe is a Microsoft Windows command shell that is completely unaware of Cygwin's shared library and by that reason it doesn't use it, so it will not call it for path translation, even if you populate the environment of zetabytes of stuff. When you run in Cygwin terminal, you are running bash shell, which is a Cygwin executable, linked to cygwin.dll. It manages to use Cygwin library for all the unix system call emulations, so when you pass it e.g. to exec("./my_script", ...);, it internally converts that to try for ./my_script, then .\my_script, ./my_script.exe, ... and the same for .com and .bat extensions.
This fact often makes some people to say that Cygwin is not a good, efficient, environment. But the purpose was not to be efficient (and it is, as it caches entries and makes things best to be efficient) but to be compatible.
In your example ls is a Cygwin executable that mimics the /bin/ls executable from unix systems. It uses the Cygwin library, so all path resolution will be properly made (well, under some constraints, as you'll see after some testing) and everything will work fine. But you cannot pretend all your Windows applications to suddenly transform themselves and begin working as if they where in a different environment. This requires some try and error approach that you have to try yourself. And read Cygwin documentation, it is very good and covers everything I've said here.

If you open up Cygwin and run the command there you should be fine.

Related

ncurses test programs failing with message "Error opening terminal: xterm"

(Note: this is similar to this question, but the answer there does not apply.)
Running under FreeBSD, I have ncurses installed via the usual pkg method for FreeBSD, but because I've seen some odd behaviour with a previously working curses program, I decided to download an ncurses source tarball from the official site and compile it under my home directory.
The compile went fine, but attempting to run any of the included test programs results in:
Error opening terminal: xterm.
The documentation does say:
NOTE: You must have installed the terminfo database, or set the
environment variable $TERMINFO to point to a SVr4-compatible terminfo
database before running the test programs. Not all vendors' terminfo
databases are SVr4-compatible, but most seem to be.
So it looks like the answer is to set TERMINFO, but to what? I don't see any terminfo database under the build directory itself, but I do have a file /usr/local/share/misc/terminfo.db installed as a result of the regular FreeBSD installation.
Nevertheless, setting (csh syntax) setenv TERMINFO /usr/local/share/misc/terminfo.db (or the same omitting the .db extension) doesn't make any difference.
(Note: this shouldn't matter because I haven't so far attempted to install the local build, but when I ran "configure", I used: ./configure --prefix=$HOME so that it would install under my home directory.
By default, ncurses uses (reads/writes) a directory-tree of terminal descriptions. Optionally (and seen in the makefile for the ncurses port), it reads/writes a hashed database file, as well as reads the directory-tree.
The INSTALL file in the ncurses sources goes into some detail about the --with-hashed-db configure option, which you apparently overlooked. The term(5) manual page gives a better overview.

Nodejs terminal script problematic cygwin paths of arguments - cannot make an universal script

I have an issue with using node.js as a script language in the Cygwin terminal. The script is used not only on Cygwin, but also on other platforms like OS X or GNU/Linux (no issue there).
Local or absolute path arguments to the script are passed as Cygwin paths (example: /cygdrive/c/Users/username/Dir/some-file.txt), but node requires Windows path (example: C:\Users\username\Dir\some-file.txt).
There is a tool cygpath that is used to translate between the two, but because of the multiplatform requirement, I cannot hardcode them. I would not like to make any bash wrappers so I can keep it a one file script.
For example this would work: ./script $(cygpath -w /tmp/file), but I cannot require the users of the script to put cygpath every time they want to use it.
Node is installed as the windows binary and is invoked with a shabang: #!/usr/bin/env node. which nodejs yields /cygdrive/c/Program Files/nodejs/node.
TL;DR: is there any sane and portable way to trigger automatic path translation in Cygwin for arguments of a nodejs script?

Linux executable on cygwin terminal [duplicate]

This question already has answers here:
Executable file generated using GCC under cygwin
(5 answers)
Closed 7 years ago.
Let me tell you my problem. I've a shell script which execute a Linux executable. I don't have access to the source code of this exe.
When I run the script on the Linux machine, there is no problem.
But, if I try to run the script on my Windows laptop, using cygwin, I have the error "cannot execute binary file".
There is any solution ?
Thanks !
From https://stackoverflow.com/a/4144536/5704102:
"... Cygwin is a compatibility layer, which aims to implement as much as possible of the POSIX and Linux APIs within Windows. This means that programs have to be compiled specifically for Cygwin ..."
What does this script look like? Is it a bash script? If so, you may want to try sh <scriptfile> in Cygwin. If this doesn't work, and it is a bash script, make sure you have sh.exe. Type sh and hit tab twice to check.
Another potential issue if it is a bash script is that you don't have something installed that Cygwin requires to run the script. Make sure all the commands the script is trying to run will work. If not, you may have to run the Cygwin installer and install whatever is needed to run the script.
Also, you may want to check permissions.
If the file has an exe extension, it SHOULD work on Windows unless it was compiled for 64 bit architecture and you're running a 32 bit OS. Otherwise, you could be missing some .dll files that the executable relies on.
Edit:
If this is the contents of your script:
echo START
/oper/file.exe
then it's likely you have the incorrect path. Cygwin paths typically start with /cygdrive/c/ in Windows. Go to where the file exists and type pwd to get the correct path, then modify your script accordingly.
Content of Script.sh in oper folder :
echo START
/cygdrive/c/Users/jo/oper/file.exe
In Cygwin terminal (in the right folder):
sh Script.sh
(Path updated)

Can't use "." to execute files with cygwin

I recently installed Cygwin on Windows 8.1, it works great but I can't execute file using the dot, for example "./hello.ml". I'm using the Windows's command prompt.
When I try using it, it show me that "." is not reconized. How can I make it works ?
Thanks.
You need to use the cygwin terminal or powershell instead.
The command interpreter doesn't think that your files are executable because they aren't one of the types that are recognized as binary executables. In general, Windows would use file associations from the registry to make things happen when you try to run a file. The cygwin terminal follows the unix-like convention and knows that your scripts are ml files and they are executable by using the ml interpreter, most likely from a #! at the top of your file.

make: pwd: Command not found

I am new to using make files. I have cygwin and MinGW. I'm still looking into their differences.
Anyway, I have a makefile that is used to create a project for an FPGA, which I have never done before. I have included C:\cygwin\bin and C:\MinGW\msys\1.0\bin in my PATH, but I always get this error.
make: pwd: Command not found
I typed pwd into the cmd prompt and get a correct response. Any pointers? Am I missing something? Not sure what else I can try. Most forums I have found pertaining to this error never have a resolution.
Let me know what information you'd like.
pwd is commonly both a shell built-in command and a standalone executable, provided by GNU coreutils (which Cygwin installs by default).
If you're invoking make from the Cygwin environment (say, typing make at a bash shell prompt), then C:\cygwin\bin is the wrong way to specify the directory. That's the path as seen from Windows. From within Cygwin, it's /bin -- and it should be in your default $PATH. The Cygwin equivalent of C:\MinGW\msys\1.0\bin would be /cygdrive/c/mingw/msys/1.0/bin
If you're doing this directly from Windows rather than in the Cygwin subsystem, then C:\cygwin\bin is the path to the Cygwin bin directory -- but running C:\cygwin\bin\pwd is going to give you a Cygwin-specific directory name that's not going to be meaningful to Windows.
I have encountered the same issue in my mingw environment. It turned out in my case to be a missing 'pwd'executable in the msys/bin directory. Once the copying was done properly, everything fell into place. Hope this helps

Resources