News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

The shebang command to run the bash script under Windows CMD

Started by ollydbg, September 11, 2021, 10:35:09 AM

Previous topic - Next topic

ollydbg

Hi, I just noticed that there is a nice project named:   https://github.com/matveyt/shebang

With this project, we can run bash script from normal Windows CMD.

Here is my test which can correctly run "wx-config-3.1"(this is a bash script) from Windows CMD.

Step 1, get and build the shebang project

You just clone/download this project.

Under your local folder, inside the msys2's mingw64 compiler command line(started by double click the "mingw64.exe" under msys2 folder)

gcc -s shebang.c -o shebang.exe -lshlwapi -DUNICODE -D_UNICODE -municode

This will generate a "shebang.exe" in the same folder.


Step 2, rename this "shebang.exe" to the bash script executable name you want

I notice in my msys2's folder, there is a bash file named:  "F:\msys2\mingw64\bin\wx-config", this file is for wx 3.0, and since I have installed wx 3.1 from pacman, there is another file named "F:\msys2\mingw64\bin\wx-config-3.1".

Now, let me try with the later script file "wx-config-3.1".

I need to copy/rename the "shebang.exe" to "wx-config-3.1.exe"

Step 3, prepare the PATH

I just start the Windows CMD window, and type something like:

set PATH=F:\msys2\usr\bin;F:\msys2\mingw64\bin;%PATH%

This will put the necessary tools in the PATH

Step 4, run the "wx-config-3.1.exe" from the CMD

Now, you can type such command inside your CMD

D:\code\shebang-master>wx-config-3.1.exe --cflags
-I/mingw64/lib/wx/include/msw-unicode-3.1 -I/mingw64/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__

D:\code\shebang-master>wx-config-3.1.exe --libs
-L/mingw64/lib   -pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.1 -lwx_mswu_html-3.1 -lwx_mswu_qa-3.1 -lwx_mswu_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1


You can see, when you run the wx-config-3.1.exe, it will internally call the msys' bash script engine.

One remaining bug:
If I run the the same command inside the msys2' mingw64 shell, I got this:


# wx-config-3.1 --cflags
-IF:/msys2/mingw64/lib/wx/include/msw-unicode-3.1 -IF:/msys2/mingw64/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__


So, it looks like the returned path is not the same in the two cases.

Any one knows how to fix this issue? Maybe, I need to add some options?




If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

stahta01

Try running the below in both places.


wx-config-3.1 --prefix


I used to use something like

wx-config-3.1 --prefix=<COMPILERPATH> --libs


Where <COMPILERPATH> was an CB variable.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

ollydbg

Hi, tim, thanks for the reply.

In-fact, I found the shebang project project on github because I see you star this project.  :)

I just try adding the "--prefix" option in Windows CMD, it gives nice result:


D:\code\shebang-master>wx-config-3.1.exe --prefix=F:/msys2/mingw64/bin --cflags
-IF:/msys2/mingw64/bin/lib/wx/include/msw-unicode-3.1 -IF:/msys2/mingw64/bin/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__

D:\code\shebang-master>wx-config-3.1.exe --prefix=F:/msys2/mingw64/bin --libs
-LF:/msys2/mingw64/bin/lib   -pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.1 -lwx_mswu_html-3.1 -lwx_mswu_qa-3.1 -lwx_mswu_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

ollydbg

The best way to use those results in C::B's option dialog is use some backtick option, such as:



`wx-config-3.1 --cflags --prefix=$(TARGET_COMPILER_DIR)`



There are some similar method I tried before:



`wx-config-msys2 --cflags --prefix=$(TARGET_COMPILER_DIR)`



Where the wx-config-msys2 comes from this eranif's project:  https://github.com/eranif/wx-config-msys2
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

ollydbg

Quote from: ollydbg on September 11, 2021, 10:35:09 AM


One remaining bug:
If I run the the same command inside the msys2' mingw64 shell, I got this:

# wx-config-3.1 --cflags
-IF:/msys2/mingw64/lib/wx/include/msw-unicode-3.1 -IF:/msys2/mingw64/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__


So, it looks like the returned path is not the same in the two cases.

Any one knows how to fix this issue? Maybe, I need to add some options?


This issue is fixed, see this github ticket: How to control the returned file path from shebang tool matveyt/shebang

The author of the shebang give me the solution.

set PATH=F:\msys2\mingw64\bin;F:\msys2\usr\bin;%PATH%

Just put the mingw64/bin path before msys2/usr/bin path.  ;)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.