Porting BASH scripts between 32 and 64 bit versions of Cygwin. - windows

I have a few simple BASH scripts, written on a 64 bit version of Cygwin.
I would like to port them them to a 32 bit Cygwin on a different PC.
What can I do to make my code run on both 32 and 64 bit versions? I would prefer code that is agnostic.
Here is what my scripts do :
Takes files from current dir and puts them in a specific directory in the C drive
Takes files from a pre-defined directory from C drive and append them in a single file
The main issue I foresee is the Windows naming scheme (for example, there are two "Program Files" and "Program Files (x86)" folders in Windows).
Other than this, are there any actual CODE or CYGWIN related problems that I may face?

I had never to port scripts from 32/64 or vice versa. Also you could ignore the Programm Files (x86) or not thing.
Porting is important when you have binary code, but not for scripts - except they will do some wired hardware dependend things.
So nothing to port - you could only make your scrpts a bit more flexible for example having parameters for path or detect in which path they have been installed.

Related

How to enable bash commands in Windows CMD?

I've two Windows machines and both have bash installed. However, they differ in the way bash starts up:
Machine 1:
Typing "bash" starts the bash. Then I can type commands like ls.
Machine 2:
It seems like it starts bash and directly runs ls in it, by only typing "ls". After that it switches back to CMD automatically, like this:
Does anyone know which setting enables the behavior of machine 2? Everything looks the same for me. It's a nice feature and I want to enable it on machine 1 as well.
Bash on Ubuntu on Windows executables (binaries) cannot run from Windows applications such as cmd.exe or PowerShell.exe - Windows doesn't even see them as executable.
The likeliest explanation is that you've installed a separate Unix emulation environment such as GnuWin, which comes with native Windows binaries.
To see the location of your - by definition Windows-native - ls executable, run where ls, which will probably tell you what product it came with, such as
C:\Program Files (x86)\GnuWin32\bin\ls.EXE.
Note that the Ubuntu on Windows binaries are stored in a user-specific manner in
%LOCALAPPDATA%\lxss\rootfs\bin, but that is a moot point, given that you cannot invoke them from Windows.
In Windows 10, there is a built-in Linux subsystem (one of the greatest features of Windows 10). It gives you almost a complete Linux shell for various distributions, and you can almost do anything with it (user mode).
I bet it is installed on your first computer, and you are using that subsystem. In the latest version of this subsystem, you can run both Linux executables and Windows exe files.

How can I execute a bash file (.sh) on PostgreSQL? On windows [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have bought and I use Windows 7 Ultimate, and I like to use it to develop applications. One of the down sides (as with every OS) is that I can not run Bash scripts. Is there a way to run Bash scripts on Windows by installing some software? It is ok if it does not work 100%, but as long as the most common functionality is available it should be great.
Install Cygwin, which includes Bash among many other GNU and Unix utilities (without whom its unlikely that bash will be very useful anyway).
Another option is MinGW's MSYS which includes bash and a smaller set of the more important utilities such as awk (you may also want to check the competing fork - Mingw-w64). Personally I would have preferred Cygwin because it includes such heavy lifting tools as Perl and Python which I find I cannot live without, while MSYS skimps on these and assumes you are going to install them yourself.
Updated:
If anyone is interested in this answer and is running MS-Windows 10, please note that MS-Windows 10 has a "Windows Subsystem For Linux" feature which - once enabled - allows you to install a user-mode image of Ubuntu and then run Bash on that. This provides 100% compatibility with Ubuntu for debugging and running Bash scripts, but this setup is completely standalone from Windows and you cannot use Bash scripts to interact with Windows features (such as processes and APIs) except for limited access to files through the DrvFS feature.
Best Option I could find is Git Windows Just install it and then right click on and click "Git Bash Here" this will open a bash window
This will open a bash window like this:
and the linux commands work...
I've tried 'sh' , 'vi' , 'ssh' , 'curl' ,etc... commands
If you're looking for something a little more native, you can use getGnuWin32 to install all of the Unix command line tools that have been ported. That plus winBash gives you most of a working Unix environment. Add console2 for a better terminal emulator and you almost can't tell you're on Windows!
Cygwin is a better toolkit overall, but I have found myself running into surprise problems because of the divide between it and Windows. None of these solutions are as good as a native Linux system though.
You may want to look into using virtualbox to create a linux VM with your distro of choice. Set it up to share a folder with the host os, and you can use a true linux development environment, and share with windows. Just watch out for those EOL markers, they get ya every time.
Best option? Windows 10. Native Bash support!
You can always install Cygwin to run a Unix shell under Windows. I used Cygwin extensively with Window XP.
After installing git-extentions (http://gitextensions.github.io/) you can run .sh file from the command prompt. (No ./script.sh required, just run it like a bat/cmd file)
Or you can run them in a "full" bash environment by using the MinGW Git bash shell.
I am not a great fan of Cygwin (yes I am sure it's really powerful), so running bash scripts on windows without having to install it perfect for me.
In order to run natively, you will likely need to use Cygwin (which I cannot live without when using Windows). So right off the bat, +1 for Cygwin. Anything else would be uncivilized.
HOWEVER, that being said, I have recently begun using a combination of utilities to easily PORT Bash scripts to Windows so that my anti-Linux coworkers can easily run complex tasks that are better handled by GNU utilities.
I can usually port a Bash script to Batch in a very short time by opening the original script in one pane and writing a Batch file in the other pane. The tools that I use are as follows:
UnxUtils (http://sourceforge.net/projects/unxutils/)
Bat2Exe (http://bat2exe.net/)
I prefer UnxUtils to GnuWin32 because of the fact that [someone please correct me if I'm wrong] GnuWin utils normally have to be installed, whereas UnxUtils are standalone binaries that just work out-of-the-box.
However, the CoreUtils do not include some familiar *NIX utilities such as cURL, which is also available for Windows (curl.haxx.se/download.html).
I create a folder for the projects, and always SET PATH=. in the .bat file so that no other commands other than the basic CMD shell commands are referenced (as well as the particular UnxUtils required in the project folder for the Batch script to function as expected).
Then I copy the needed CoreUtils .exe files into the project folder and reference them in the .bat file such as ".\curl.exe -s google.com", etc.
The Bat2Exe program is where the magic happens. Once your Batch file is complete and has been tested successfully, launch Bat2Exe.exe, and specify the path to the project folder. Bat2Exe will then create a Windows binary containing all of the files in that specific folder, and will use the first .bat that it comes across to use as the main executable. You can even include a .ico file to use as the icon for the final .exe file that is generated.
I have tried a few of these type of programs, and many of the generated binaries get flagged as malware, but the Bat2Exe version that I referenced works perfectly and the generated .exe files scan completely clean.
The resulting executable can be run interactively by double-clicking, or run from the command line with parameters, etc., just like a regular Batch file, except you will be able to utilize the functionality of many of the tools that you will normally use in Bash.
I realize this is getting quite long, but if I may digress a bit, I have also written a Batch script that I call PortaBashy that my coworkers can launch from a network share that contains a portable Cygwin installation. It then sets the %PATH% variable to the normal *NIX format (/usr/bin:/usr/sbin:/bin:/sbin), etc. and can either launch into the Bash shell itself or launch the more-powerful and pretty MinTTY terminal emulator.
There are always numerous ways to accomplish what you are trying to set out to do; it's just a matter of combining the right tools for the job, and many times it boils down to personal preference.
There's one more theoretical possibility to do it: professional versions of Windows have built-in POSIX support, so bash could have been compiled for Windows natively.
Pity, but I still haven't found a compiled one myself...

Why can I not see winlogon.exe using Python on top of Cygwin?

This is the file I'm searching for on a Windows XP computer
C:\Windows\System32\winlogon.exe
I have displayed file extensions for all files, checked Show Hidden Files, checked Show Hidden System Files, and I can see the file using Explorer but cannot see the file with python. I cannot even see the file using:
os.system( 'dir C:/Windows/System32/winlogon.exe' )
I can see the file by using command prompt by running
dir C:\Windows\System32\winlogon.exe
Python's documentation: "On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists."
I'd like to use the regular python libraries to be able to do this. I also tried open() command. How do I go about finding this file using Python?
Note: I'm running Python27 under Cygwin in Windows XP. This is because I'm in networking and it's easier to write scripts that run off of Linux, ssh into Windows' Cygwin sshd client, in order to run things.
The issue was that I was using 64 bit Windows with 32 bit Cygwin. Apparently 32 bit Cygwin can only see 32 bit files while 64 bit Cygwin can see all the files.
Source: http://cygwin.com/ml/cygwin/2006-01/msg00444.html
This may be true for all 32 bit applications running on a 64 bit environment. Another reason for many 32 bit applications to upgrade to 64 bit if the applications plan to be run on present 64 bit machines.

VB6 Legacy Code can't "Call Shell"

I am working on some legacy VB6 code and I am having my program break with this message:
and it then highlights this code:
I know that the specified locations exist per these screenshots:
I am running this Visual Studio 6.0 on a 64-bit Windows 7 machine. How can I make the program see shell?
command.com does not exist on 64 bit windows.
Try using C:\Windows\SysWOW64\cmd.exe instead. C:\Windows\SysWOW64 is a folder giving you backwards compatibility stuff for 32 bit.
But see the comment below (taken from Euro Micelli).
Really you should use %SYSTEMROOT\System32\cmd.exe instead. First, Windows is not always installed in C:\Windows; you should let the system figure that out. Second, using System32 is always correct for a 32-bit application: when running on Win32, it is the correct folder; when running on Win64, Windows will map %SYSTEMROOT%\System32 to %SYSTEMROOT%\SysWOW64
I use vb6 and windows 7.
I've done the same thing as you but I put the dos command in a bat file.
Login.bat
NET USE W: \\10.48.10.8\e$
Then in the code
Shell ("c:\login.bat")
The vb command is not correct for the OS that you are running. You need to check that that drive is not already mapped, and remove the command.com /c from the command that you are trying to execute.

Using mingw/msys just for its posix tools: mount point question

I write cross-platform software, so I like my Windows environment to be Un*x-like (I'm an old Unix/IRIX/Linux geek). I just care about shells and tools, not so much about compilers or the build environment (I have a real industrial-strength build system that doesn't depend on mingw or cygwin). I just want a shell window on my Windows box that works like a POSIX system.
I'd like to move away from cygwin and its CRLF weirdness and dll-dependencies and update troubles, and maybe replace it with mingw/msys. I've started to do this, but am stumped on one thing. I really really need mingw paths to map to the same Windows paths. So / must be c:/ and /windows -> c:/windows and so on. Mingw's default mount setup ends up like a chroot, with mingw "/" mapping to c:/mingw or something like that. You have to use drive prefixes like /c/windows to get to /Windows. I'm happy to tweak my $PATH and whatever else I need to do to make this work. Does anyone have any hints?
You can install Cygwin into C:/, in which case / does become C:/. Dunno whether that can be done with MSYS.
Btw, MSYS is a fork of Cygwin 1.3.3 from 9 years ago, which hasn't seen an awful lot of development compared to Cygwin proper. It has the same approach to line ending issues, allowing both binmode and textmode mounts.

Resources