Test a shell (.sh) file in CLion - c++

I am using Clion and I am unsure how to run a .sh file with my code. It is for an assignment, and I have to run an automatic test to test my code.
This is how it is described to be called: $ ./test_p2.sh 2
I have the shell file in the folder with my code, But I cannot see it in executable or working directory.
Any help is appreciated! Thanks

You can't directly run Linux shell scripts on Windows. You do have a few options, however:
Run your script through Cygwin
Run your script in mintty (this is the shell included with Git for Windows, is called Git Bash in the context menu)
Run your script under WSL (Windows Subsystem for Linux)
Port the script to another language you can run on Windows
For 1 and 2, it'll be on you to make sure any dependencies for the script are available in either Cygwin or mintty.
For 3, after making sure WSL is set up you can run a single command under WSL: wsl script.sh arg1 arg2 argX.
I would recommend option 3 or 4. 3 may offer the best experience in terms of compatibility and ease of set up (without porting the script) as Cygwin and mintty can be a pain to set up dependencies in. Option 4 would be best though as long as you are well-versed in both PowerShell and shell scripts and can transpose the equivalent calls from one to the other.

Related

Building a Windows Console App In Cygwin 1.7.16 Targeted to Cygwin 1.5.24

I have a Windows console app that is pure standard C++. I am building it in Cygwin 1.7.16 (running on Windows 7) for target Cygwin 1.5.24 (running on Windows XP SP 2).
My build command is:
g++ -o mgen_stats.exe -I ../include ../src/*.cpp
On the target, my path includes /usr/bin, which is where cygwin1.dll lives.
When I run the application with no arguments on the target in a Cygwin 1.5.24 shell, I immediately get the command prompt back. I should see the application's usage printed out.
Some immutable constraints I'm working under:
The build and target machines are isolated from each other.
There is no C++ build tool chain on the target.
I may not install a C++ build tool chain on the target.
I may not modify the C++ build tool chain I have on the build machine.
As a result of the above, I must build on my build machine, burn the .exe to a CD, and copy it onto the target machine.
I would be just as happy for my application to be a native Windows application (i.e. run it in a DOS shell rather than a Cygwin 1.5.24 shell). To this end, I tried using g++ build flag -mno-cygwin. g++ tells me that flag -mno-cygwin has been removed. It then suggests that I "use a mingw-targeted cross-compiler". I do not know how to tell if I have the mingw-gcc, mingw64-i686-gcc, and mingw64-x86_64-gcc packages (which, according to the Cygwin FAQ, contain the suggested cross-compilers), and if I do have them, I do not know what the names of the compiler executables are.
Can anybody help me get this app built such that it will run successfully under either a DOS or Cygwin 1.5.24 shell on my Windows XP SP 2 target?
Thank you in advance.
The MinGW packages (like any other Cygwin package) can be installed on Cygwin using the "setup.exe" that Cygwin provides on its website. If you do have them installed, you'll find the compilers as i686-w64-mingw32-g++ or x86_64-w64-mingw32-g++.
Alternatively, you can also install the MinGW packages directly (without using Cygwin).

Getting mingw-get to install correctly - mingw/msys path missing plus more!

I'm running windows XP.
I have been following this tutorial and so downloading mingw-get-inst here.
I've done this a couple times and the last time I checked boes to install EVERYTHING including, but not limited to, gcc, g++, MSYS and the MinGW Compiling Suite. I told it to make a program menu shortcut, too.
I believe I have correctly added MinGW/bin to the Environment Settings' Path.
So I have the shortcut to the MSYS shell now. It goes to C:\MinGW\msys\1.0\msys.bat, but the whole msys directory does not exist!
There are tons of "packages" have been downloaded as far as I can tell ("mingw-get show" brings up a lot!), but it doesn't seem like any of it installed correctly.
Also, should I be able to use commands like "g++ foo.cpp -o foo.exe" from cmd.exe or only from the MSYS shell? Because I was unable to use cmd.exe.
Please help!
The MSYS and MinGW installation procedure is a nightmare, and has got worse over the years. If you just want the compiler suite (no UNIX tools like sed, grep), then I suggest you go to Twilight Dragon Media and download GCC from there. If you also want all the tools, including the Bash shell, the easiest way I've found to get them is to install Git for Windows (which you may want anyway), which includes them all. And if you want a C++ IDE that works well with GCC, take a look at Code::Blocks.
What is the result of running, at a cmd.exe prompt, the command echo %Path%? It should (given what you wrote about your system) include “C:\MinGW\bin”—does it?
What is the result of running dir C:\MinGW?
Note that mingw-get show shows details of available packages—those mingw-get knows how to download and install. The installer is a bit primitive, but has gotten better over the last year or so.
If you issue the command $ echo $PATH, you'll notice it contains /mingw/bin But the /mingw directory is unavailable. To mount it, edit the MSYS fstab, adding a line like C:\MinGW /mingw For details, see the MingW Getting Started guide, more specifically section "After Installing You Should..."
You only need to add MinGW/bin to the Windows' Environment Settings' Path if you plan to use MingW's executables outside of MSYS.

The equivalent of ./configure in Windows?

What is the equivalent of ./configure in Windows?
Sometimes I download a C/C++ library and when I use the make it, it says "use ./configure" but obviously ./configure can only be used on a Linux machine and the libraries don't usually have instructions for compiling on Windows (although they do support Windows, they don't provide instructions).
For example, the library wxSVG says it works on Windows, but when I download it I don't see any instructions for compiling on Windows, and I only Linux files for configuring it.
I just faced with the same issue and here is what I did,
I first installed MinGw using the installation manager (with msys base included). Then I go to C:\MinGW\msys\1.0\ folder in my pc, where msys.bat (to evoke the MinGW shell) and run it. Then on that bash screen, I navigated to the folder that I wanted to install initially. After that, using "./configure" and "make" worked just fine.
Actually, ./configure is not Linux-specific at all. Its original purpose was to smooth over the differences between the many variants of Unix now thankfully relegated to the dust heap of history, but nowadays it may well know how to set up things to work on Windows.
I would install the MinGW/MSYS development tools and see if the configure script is happy in that environment. (If that doesn't work, I can't help you any further.)
./configure is a script that comes with the source you have downloaded. You will use it the same on windows as you do on any other operating system. Unfortunately, you will need a posix-like shell to run it. A good option for that is to use mingw or cygwin
I'd say that this is program dependant. You see "configure" is a program/script in the local directory, it's not a global command/program (like "dir" would be)...
You either have luck to find something like "configure.bat" or "configure.cmd", or you'd have to adapt the configure-file into a BATCH-file.
You only run the ./configure command when building certain applications from source.
So Unzip it where you want to install it and then go to the folder where you unziped it and run "./configure"

Invoking MSYS bash from Windows cmd

I'm using GCC on Windows 7 (using the TDM's build). I installed MSYS to be able to execute Make and compile using makefiles. However, it is tedious to every time start up the MSYS Bash shell, navigate to the directory of the project and run make.
What I want is to automate this process. I prefer to have a batch file in Windows, or something similar, from which I then invoke the MSYS Bash shell. It should navigate to the directory the batch file resides in and call make.
Is this possible? Can I send commands to MSYS Bash from cmd (like navigation/invoking make)? Or can I let the MSYS Bash run a "Bash script", which sets the commands to be executed much like batch scripts?
PS: This is something similar to Stack Overflow question Executing MSYS from cmd.exe with arguments.
Not an MSYS expert, but does something like this work for you:
rem Call this something like compile-project.bat
c:
cd \src\project
bash -c "make"
You don't have to use bash to execute make, or any of the other MSYS programs. If you put the MSYS bin directory on your path, you can execute them from a Windows command shell. Alternatively, the bash shell has an enormously powerful scripting language built in. But I'm not clear if that's what you are asking about - you should clarify your question with an actual example of what you want to do, spelling out the steps you want automated.
My own setup is to have a Windows Explorer context menu called "Bash here" which opens a bash shell in the directory I select. This is done via the following registry entries:
[HKEY_CLASSES_ROOT\Directory\shell\mybash]
#="Bash Here"
[HKEY_CLASSES_ROOT\Directory\shell\mybash\command]
#="cmd /c c:\\bash.cmd %1"
And the following bash.cmd file in c::
#echo off
title bash
cd %1%
bash
Note that the MSYS bin directory is on my path. And of course, any registry hacking is at your own risk.
Just add executables to your Windows PATH:
C:\msys64\mingw64\bin
C:\msys64\usr\bin
Keep in mind, this adds a lot of executables to your path which might conflict with other applications. The ..\usr\bin directory contains all installed MSYS2 packages. There is a lot of unnecessary stuff. ..mingw64\bin directory has a smaller list.
Source
On my MSYS-1.0.11 with the MSYS developers packages, I can call a bash script (CurrentScript.sh) with a cmd/bat file in the current folder with this command:
R:\MinGW\MSYS-1.0.11\bin\sh "%cd%\CurrentScript.sh"

g++ not working on Windows command prompt. Cygwin installed

I have installed Eclipse and CDT (to use C/C++ in eclipse CDT is needed), as well as installing Cygwin so that I can compile my files.
In environment variables I've set Path to include the following: "C:\cygwin\bin;"
g++, make and GDC are all installed via Cygwin. I made sure of this by searching for them in the bin folder - they're all there.
If I enter "make" into the windows command prompt, this appears:
make: *** No targets specified and no makefile found. Stop.
If I enter "g++" or "gdc" into the windows command prompt, this appears (or similar):
'g++' is not recognized as an internal or external command,
operable program or batch file.
So, in other words make is working but the rest isn't..but they're in the same bin folder! Has got me completely confused.
If I attempt to open Cygwin Bash Shell, g++, make and GDC all work there.
However, I need it to work in the command prompt so that Eclipse is able to compile the programs I write in the IDE.
If you know why this is happening, please let me know.
I haven't used cygwin much, but my understanding is you have to use it from the cygwin bash shell.
if you need g++, make, etc, use mingw, with it, g++ works from the normal windows command line.
Here is what happened to me and how I fixed it.
My C:\cygwin\bin\g++.exe is a shortcut pointing to C:\etc\alternatives\g++.exe, which points back to C:\cygwin\bin\g++-3.exe.
Replacing g++ with g++-3 worked for me.
In C:\cygwin\bin see whether g++.exe is there. If not, the installation wasn't done properly and you may need to install again. That's what was my problem and it's resolved :)
Adding the cygwin paths to the Path variable worked for me (windows 8.1 64 bit):
Go to system properties and select advanced system properties
Go to environment variables and select Path in system variables, click edit
Add the Cygwin paths...
for 32 bit:
C:\Cygwin\bin;C:\Cygwin\usr\bin
for 64 bit:
C:\Cygwin64\bin;C:\Cygwin64\usr\bin
In the CMD window, try typing bash to start a bash shell in that window. If that doesn't work, then the cygwin bin directory is not on your path.
If it did work, enter type g++ and type make to see the paths that are being used for these commands. I'm pretty sure your problem is with your PATH variable.
You could install a Windows version of which to get some help in figuring out exactly which executables are being run.
Perhaps it's picking up 'make' from somewhere completely different, and your addition to %PATH% is not working.
Also verify it by typing echo %path% in the same command prompt window as you're seeing the problem in, just to make sure.