I'm writing a little batch script, and i'm trying to execute two different commands in a new command window.
Now, the window opens, but i'm unable to execute the commands in sequence.
Here's the code:
:KARMA_TEST_START
ECHO.
start cmd /k gulp compileUnit && karma start
GOTO MENU
I've tried everithing mentioned here: How to run two commands in one line in Windows CMD? but with no luck.
I'd like the new window to open, execute gulp compileUnit, after that, execute karma start and stay open (cause karma start should listen to changes and re-run every time by itself, that's why i need it to stay open).
Any help? thanks
Use: start cmd /k gulp compileUnit ^& karma start. As you have it, the two commands are the start command and karma one. This way, both commands are passed as parameters of start. If you want to insert two ampersand characters (for conditional execution), use ^&^&.
Related
I want to run a new cmd window from a batch job in jenkins and then hand over commands one by one to that new cmd.
I know I can start a new cmd and run some commands like this:
start cmd.exe /c "cmd1 & cmd2 & cmd3"
As I have a lot of commands to execute, I'd prefer not to chain them as in the example above, but start a new cmd and then execute each command separately.
Is there a way I can achieve this? I know I could do that by calling a separate batch file with the commands, but some of my coworkers will only have access to jenkins and therefore we need a posibility to have a look into the commands and to change them.
I have another bat file that I'm running, and once in the command prompt that bat file creates, I want to run another command in that window.
Here's what I have so far:
call C:\Batch\MyBatFile.bat (this creates the new command prompt that I want to use)
C:\Program\MyProgram.exe
However, the second line is being run in the original window, instead of the new command prompt. I tried using start C:\Program\MyProgram.exe, but that just ran in a 3rd new window instead.
If it's relevant, the first line is just setting a few environment variables that I need access to and MyProgram is a visual studio 2010 project. Technically, I might be able to modify that bat to run the command, but I'd rather avoid that solution as that bat file isn't owned by me (and thus whenever it's updated I'd have to update mine as well).
Thanks in advance.
You could try to inject your program.exe into cmd created by batfile.bat by redirecting it's input stream and then sending it a command, eg. echo C:\Program\MyProgram.exe | C:\Batch\MyBatFile.bat. This assumes that batch really just sets bunch of variables and does not use commands which reset/consume input stream.
Please note that if redirected/piped this way new command window will not stay open It will maybe :-) just execute your command and then close/exit.
Create a CMD script to run both of the commands that you have shown in the question. Maybe call it RunMyProgram.cmd. The contents are just the two lines that you have:
REM Source the environment variables.
REM Any new command prompt window that is opened can be ignored
CALL C:\Batch\MyBatFile.bat
C:\Program\MyProgram.exe
If what you have stated in the comments to your question is accurate regarding MyBatFile.bat setting up the environment variables and then starting a new window, then you should be able to make use of those environment variables after MyBatFile.bat exits.
If running RunMyProgram.cmd from a command prompt still has MyProgram.exe giving the error when the environment variable is not set, or if MyProgram.exe doesn't even start to run until you close the new window that popped up, then we need to see the exact commands that MyBatFile.bat is executing.
On a Windows 7 machine if I run a PHPUnit Selenium command like this manually in the terminal:
phpunit --verbose --log-junit _selenium_tests\results\home.xml _selenium_tests\frontend\home.php
It spawns a browser and runs the test just fine. Then it outputs the following on the screen:
Time: 10 seconds, Memory: 3.50Mb
OK (1 test, 3 assertions)
And the terminal stays open.
Now if I copy and paste the exact command in an empty file and save it as test.bat and click it, it also runs the test. I can see the browser open and all tests run. Only problem is it closes the terminal prompt right after. So I can't see the above output.
An even bigger problem is, since it closes the terminal if I add more commands for other tests after that initial one they don't run.
I tried adding:
pause
at the end of the bat file but no luck, it still closes. Any idea how to prevent this and be able to run one command after another without the terminal ever closing?
Your question is similar to this one. Try using call in front of your command. If you run a .bat file from another .bat file and don't use call, control doesn't return to the first batch file, so pause doesn't get executed.
Try cmd /K phpunit --verbose --log-junit _selenium_tests\results\home.xml _selenium_tests\frontend\home.php
The /K option in cmd /K string Carries out the command specified by string but remains,see http://www.computerhope.com/cmd.htm
Also, I don't know the file type of the phpunit command you execute - I'm not familiar with selenium. If it is batch file (i.e. ends with .bat), you just can't call them from another batch file: everything below the call to the second batch file will never get executed.
You then need to use the CALL command. CALL Enables a user to execute a batch file from within another batch file, see http://www.computerhope.com/call.htm
I wonder if I can execute some programs for different cmd's using .bat file. Look at this example .bat file:
start cmd //number one
start cmd //number two
ping localhost //call in number one
ping 192.168.1.100 //call in number two
I know that both will be executed in main window (the window where I started .bat file), but I think its easy to get the idea. This code is quite useless, but its just an example.
Thanx for all replies.
EDIT: I know about /k switch, but any way to do this not using it?
You can start your commands with
start cmd /k ping localhost
start cmd /k ping 192.168.1.100
That will start two new command line prompts, run the ping command in each one seperately and both windows and the /k switch will make them stay open afterwards.
Ah, posted before your edit ... ;) The only way to interact with a shell is giving it a command to be executed when it starts. There is no way to have interaction between shells
CMD.EXE has two parameters, /C and /K, which let you specify a command to execute. /C closes the window when the command is finished, whereas /K keeps it running.
If you want to excute multiple commands within a single window, you'll need to concatenate them with && or similar - this will require quoting; CMD /? will tell you all the details on that - or you can have it start a batch file containing the commands.
I have a program that changes my desktop wallpaper by dragging the picture file onto it. I also have a wireless network program that can auto open programs everytime it connects to a certain network.
I want to change my desktop everytime it connects to a certain network, but running the wallpaper program doesn't do anything unless I drag the picture onto it. However, I can also run a cmd prompt "c:/program.exe picture.jpg"
I tried creating a batch file START C:/PROGRAM.EXE PICTURE.JPG, but it doesn't work.
So basically I am trying to create a program that can run the cmd prompt "c:/program.exe picture.jpg" - can you help, please?
Remove the "start" from the batch file, and make sure any paths with spaces in them are enclosed in quotes, otherwise they'll be broken into arguments.
For example:
"C:\Program Files\MyProgram.exe" "C:\Documents and Settings\Me\MyPicture.jpg"
A batch job should work. Try skipping that START from your example.
Start - Run - Type :
cmd /c "start /max ""C:\Program Files\MyProgram.exe"" ""C:\Documents and Settings\Me\MyPicture.jpg""" .
The cmd /c - starts a new cmd instance and quits