Program executing twice after compilation - compilation

I have made a small test c++ file, called main.cpp in programmer's notepad.
#include <iostream>
using namespace std;
int main()
{
cout << "hello";
return 0;
}
I use Mingw and compile using the windows cmd shell:
g++ -o Test main.cpp
The program compiles without errors and Test.exe is created. When I try to run it in de command shell it first opens a new command shell, runs the program, closes this new command shell and then runs the program again in the first command shell.
The same happens when I browse to the folder and click the executable. It opens a command shell, runs the program, closes the command shell and does this again in a second command shell.
Does anybody have an idea of what could be going wrong here? Are my compiler setting wrong or something like that? I'm not very experienced with setting up compilers so it probably is something pretty basic.

i had exactly the same problem and finally stumbled accross this post:
Visual Studio 2013 runs project twice
so if you are using Avast as antivirus just disable deepscreen and your programs only run as often as you desire it ;)
/edit: any antivirus using cloud scan could cause this behaviour

Related

how to run .sh file in Ubuntu using installScript

I am creating an installation using InstallShield 2018 in windows 10. I need to execute a script file (.sh) in Ubuntu from a function in Installscript. I tried the following but it did not work:
szCmdPath = "C:\\Users\\Admin\\AppData\\Local\\Microsoft\\WindowsApps\\Ubuntu.exe";
szCmdLine = ". /mnt/d/test.sh";
LaunchAppAndWait( szCmdPath, szCmdLine, WAIT);
However I can execute the exact same file in Ubuntu Terminal and it works great. I did turn on Window sub system for Linux and install Ubuntu on windows. Why is this happening? Why can I run cmd.exe from installscript but not Ubuntu?
Thank you in advance.
EDIT 1: if I pass an empty string as parameter, Ubuntu is start and waits for my input commands. But when I pass the path to my script file, nothing happened except a flash of the terminal console before my installation goes on running.
From my reading, wsl and ubuntu differ slightly. It looks like wsl is a bit magical and occasionally similar to bash -c or ubuntu -c, whereas you can consider Ubuntu.exe as somewhat equivalent to /bin/bash.
If you try to run /bin/bash . /mnt/d/test.sh from a bash prompt, things don't go well. So the correct approach will depend on the contents of your script and what you need to happen. I think one of the following options are the most likely:
remove . from your command; instead run ...\Ubuntu.exe /mnt/d/test.sh
add -c to your command; instead run ...\Ubuntu.exe -c . /mnt/d/test.sh
Note that %LOCALAPPDATA%\Microsoft\WindowsApps\Ubuntu.exe is a special file (zero bytes), so it's also plausible that it needs some special handling. For instance, maybe it requires a 64-bit caller. If that's the case, you may need to wrap it in a call through a 64-bit cmd prompt. My quick tests don't show this as likely, however, so I think it will work without this extra indirection.

gfortran compiler on windows powershell not creating executable

The title says it all really, I run gfortran to compile a simple test fortran program, it compiles with no errors; but when I run ls to look at the output, there is no executable created. I've tried with the -o option set as well.
The fotran program is a simple hello world
program test1
implicit none
print *, "Hello World!"
end program test1
(The gfortran I'm using is from the mingw release; I have aliased gfortran to c:/mingw/bin/gfortran.exe within powershell, but the same problem happens if I call it explicitly)
Has anyone had this problem before? I thought it might be a permissions issue but I can create files from powershell just fine (unless gfortran needs additional permissions for some reason?). Any help greatly appreciated, thanks :)
Turns out simply aliasing the path to the compiler doesn't work in powershell for MinGW, adding the mingw bin directory to the path is necessary and solved my problem as #cup suggested in the comments. Thanks everyone :)
I just happened to have the same problem that you described but two years later ...
I found that I just need to call the program as ./test.exe instead of test.exe, as I would have done with MS-DOS. That way I do not have to change the path if I work in a different folder.

Break the current program without exiting VIM

When using VIM, I usually like to run programs by using the bang in command mode.
That is, use
:!<external shell command>
to test code without exiting vim or alt-tabbing to another open shell. So for example, when writing Java code, I might do something like
:!java Main
Or in C, maybe
:!cls & gcc -g -o main Program.c File.c & main
This works fine. The VIM window turns into a shell, my program runs, and then upon exit I get back into VIM.
The issue is when my program hits an infinite loop. I get stuck with the terminal displaying the standard output and then I can't get back to VIM. Control-C exits EVERYTHING and then I need to re-open VIM and re-open all my files and it's a big mess (especially if I didn't save something!).
tl;dr Is there a way to stop internally-running externally-defined shell commands in VIM?
In my case, Ctrl-c works just fine.
I am on vim 7.4 on ubuntu 14.04.
Control-z works instead of Control-c

Interpreting F# files with Mono

After installing F# on OS X with Homebrew, In Haskell (with GHC), it's possible run code on an interpreter. I was wondering if there is a way to run files without compiling them first in F#? Maybe with fsharpi?
Just to clarify, I do not mean the REPL itself, but running an app without intermediary files.
You can use fsharpi which is an interactive mode for F#. You can just start fsharpi and then type F# code in the console that starts:
> 1 + 1;;
val it : int = 2
You can also write your code in a fsx file and pass it to fsharpi to have it executed. Say you have demo.fsx with:
printfn "Hello world"
You can then run fsharpi demo.fsx and it should print hello world for you!
Some people use F# from command line in this way, but it gets more productive if you setup your favorite editor to use F# - then you can type code directly in the editor and send it to F# Interactive using some command. There are good plugins for Atom, Emacs, vim, Sublime and others - see the links here.
PS: It is worth adding that F# Interactive does not actually interpret the code. It compiles it on the fly and runs it, so it has the same performance profile as compiling the code in the usual way.

Can't run program in debugger?

I was trying to use gdb on a program earlier on a Linux 64-bit machine, and I ran gdb bomb (that's the program name), and within gdb, I simply typed in ran. It came back with the error /bin/bash: /home/imicrothinking/ics11302016004/lab2/bomb: No such file or directory During startup program exited with code 127.
I've dug around the net for a bit, and suggestions I've heard so far led to no concrete solutions, here's what I'm sure of so far:
I'm logged on as a root level user.
I haven't gone to the wrong directory.
The executable file definitely exists.
I'd welcome all suggestions.
maybe gdb cann't find your shell. so set the env var SHELL to your shell.
eg: export SHELL=/bin/bash
ref : http://www.linuxquestions.org/questions/linux-software-2/gdb-giving-wierd-error-169299/

Resources