Use different command executor in vscode task - powershell

I have a task I'm using to run the make command for a build process in vscode. I want this command to be run in a specific environment instead of powershell since it has unix like calls in the makefile. I would like to use bash (git bash) or any shell binary instead.
The error I'm getting from the task for reference: The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command make" terminated with exit code: 1.
Thanks in advance

Related

Create a task with task Scheduler to run cmd.exe with commands

I created a task with the task scheduler in windows 10 to open cmd.exe. it ran successfully like this
But I need to run some commands every time it opens something like this
and automatically runs this command.
this is important that it opens a command prompt first and then runs the command inside the command prompt automatically.
Thanks.
Use /k flag. See cmd.exe /k switch.
If you don't need console window to stay after commands completed use /c flag. You can read more about them with cmd /?

Run bash script in WSL through powershell script

I am trying to run a script which launches a WSL (ubuntu1804) terminal, and then run a bash script in that terminal
.\ubuntu1804.exe;
cd test_directory;
node server.js;
However after the first command the terminal open however, the two other commands aren't executed
.\ubuntu1804.exe by itself opens an interactive shell which PowerShell executes synchronously.
That is, until you submit exit in that interactive shell to terminate it, control won't be returned to PowerShell, so the subsequent commands - cd test_directory and note server.js - are not only not sent to .\ubuntu1804.exe, as you intended, but are then run by PowerShell.
Instead, you must pass the commands to run to .\ubuntu1804.exe via the run sub-command:
.\ubuntu1804.exe run 'cd test_directory; node server.js'
Note: Once node exits, control will be returned to PowerShell.

Perl keeps flashing when running command Windows 10

I have installed Perl but every time I run a command it flash and goes away and does nothing, I have added it to Environment path and gave full permission to folder Perl64
edit regeristy in perl command c:\perl\bin\perl.exe %1 %*
when I run Perl -v I do get versions so I know it installed
It sounds like your command ran to completion and exited. Once the program exits, the console is closed.
Perhaps you are getting an error. You should run the program from the command line to see what errors you get.
You could also try associating the file with the following command:
cmd /c c:\perl\bin\perl.exe %1 %* & pause
(Untested)

Run two auto exit batch process without exiting command prompt after 1st process complete

I am new in writing batch files on windows machine.
Here is the process
cd \
cd C:\bbCode
webpack --env=dev
cd \
cd C:\Project\bbCode
cordova run android --device
My problem is when webpack command run and when is finished, it exit the terminal without running next line of commands.
How to run other line of commands without exiting terminal after webpack is finished.
*Note : webpack and cordova are the commands to compile my code and build apk file respectively.
assuming webpack is a batch file (you don't say...) then
CALL webpack --env=dev
Since call didn't work and webpack has unknown extension, then
start /wait "" webpack --env=dev
may fit the bill
I think you need to use EXIT command between two actions
CALL Action1
EXIT
CALL Action2
Instead of EXIT you can try :
EXIT /B 0

Cygwin - run script silenty from "run command"

I have script lets say:
C:\foo.bsh
I want to be able to run this command via the windows run command:
Start -> Run
Windows Key + R
and type something small like 'foo' and hitting return.
However, I do not want a cmd prompt to be visible. This script does some preprocessing for an IDE. I do not want the cmd prompt to be open for the lifetime of the IDE process.
I have tried:
1) Creating a bat file with the following contents:
c:\cygwin\bin\bash --login "C:\foo.bsh" (this fails because it keeps a cmd open)
2) Converting the above bat file to an exe using bat_2_exe_converter (does not make the cmd silent)
thoughts?
EDIT: The solution so far suggests something to type from an actual cygwin shell. I am trying to get a faster solution by having something short I can type in the Windows run command. Also, the nohup command; exit doesn't automatically kill the box - however I can manually kill it without killing the IDE process. The run command accepts shortcuts (.lnk's), bat's, exe's.
Try the run.exe command of cygwin. It is a big install, a complete unix environment for your Windows machine. Suppose you installed it at c:\cygwin\.
No mystery, just run c:\cygwin\bin\run.exe <your command here> and you will have your no dos window execution.
You can run it from any DOS window (run cmd.exe from the start menu). You don't need to run it from cygwin.
To make it easier, append C:\cygwin\bin to your %PATH% env var (My Computer → Properties → Advanced → Environment Variables) (Kudos to Felipe Alvarez comment).
Now you can just type
c:\cygwin\bin\run.exe "C:\foo.bsh"
You must create a link in your Start Menu with this command so will be able to run it with Win-R.
Here is the man page of the runcommand:
$ man run
RUN(1) run 1.3.0 RUN(1)
NAME
run - start programs with hidden console window
SYNOPSIS
run [ -p path ] command [ -wait ] arguments
runcommand [ -p path ] [ -wait ] arguments
DESCRIPTION
Windows programs are either GUI programs or console programs. When
started console programs will either attach to an existing console
or create a new one. GUI programs can never attach to an exiting con‐
sole. There is no way to attach to an existing console but hide it if
started as GUI program.
run will do this for you. It works as intermediate and starts a pro‐
gram but makes the console window hidden.
With -p path you can add path to the PATH environment variable.
Issuing -wait as first program argument will make run wait for program
completition, otherwise it returns immediately.
The second variant is for creating wrappers. If the executable is
named runcommand (eg runemacs), run will try to start the program (eg
emacs).
EXAMPLES
run -p /usr/X11R6/bin xterm
run emacs -wait
runemacs -wait
run make -wait
AUTHORS
Charles S. Wilson
Harold L Hunt II
Jehan Bing
Alexander Gottwald
Version 1.3.0 November 2005 RUN(1)
You can use either...
c:\cygwin\bin\bash -l /path/to/script_to_interpret.sh
...or...
c:\cygwin\bin\bash -l -c /path/to/executable_script.sh
Note: the -l flag tell bash to "act as if it had been directly invoked by login" and use Bash Startup Files. This is important in that it sets your $PATH and other things you rely on when you launch a cygwin terminal. If you don't include -l or --login you will get "command not found" when you try to call anything except of a bash builtin.
The difference between the 2 is like the difference between doing...
bash script_to_interpret.sh
...and...
./executable_script.sh
...in *nix. The former interprets the script using bash. The latter executes the script (only if it has chmod +x executable_script.sh) and interprets it according to its "shebang" line. The latter method is also what you want to do if your executable is not a script at all, like a *nix binary compiled from source.)
It has been bugging me for a while I couldn't find the solution for this, but I finally got the right mix together.
You can simply do the following if you have cygwin on your PATH:
run bash test.js
If cygwin is not on your path, you can do this:
c:\cygwin\bin\run.exe -p /bin bash test.js
If you are looking for more control over the created window (maximize, etc) it looks like you can use cygstart also.
Sources:
- neves answer above (though that wasn't enough by itself for me personally to figure it out)
- http://cygwin.com/ml/cygwin/2008-09/msg00156.html
As the terminal can't close while your script is still running, try the command:
"nohup C:\foo.bsh; exit"
This way your script will be backgrounded and detached from the terminal, and it should exit quickly so the terminal goes away. I think that the window may still 'flash' with this approach, but the results should be better than what you're getting.
I'm running Cygwin64 and the xwin server link points to:
C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe
This creates an icon AND a notification on the taskbar. I don't like that. The icon is rather useless, the notification has all your menu options from .XWinrc.
So... I wrote a .vbs script to silently run this command and make the icon go away:
Set objShell = CreateObject("WScript.Shell")
objShell.Run("C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe"), 0
Another imperfect possibility is to run the script via a shortcut and set the shortcut's Run option to "minimized".
Go to the directory where you have installed cygwin(on my machine it is c:/cygwin64/bin)
Once there simply type "bash.exe"