nircmd: I can't run another batch file with nircmd.exe? - windows

I have wrote a batch file that i want to run another program with nircmd.exe. But the problem is i can't run it? The batch file(Matrix.bat) runs correctlyby double-click it. But when i trying to open it with nircmd.exe, it doesn't run? why?
i tried two method:
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
start %INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
%INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat

The exec command in nircmd does not run batch files but executable files. Change your code to
start "" "%INSTALLPATH%\nircmd.exe" exec show "%comspec%" "%INSTALLPATH%\Matrix.bat"
Now, nircmd executes a cmd instance that will handle the batch file execution

The problem was in path of nircmd.exe. I set path of nircmd but i didn't know why it isn't work correctly? with "pushd" command i set the path of cmd into where nircmd.exe exist. and Bow!!! everything works cerrectly. Maybe a syntax problem. If everyone know that say it here.
SET INSTALLPATH=d:\atlantic
pushd %INSTALLPATH%
nircmd exec show Matrix.bat

Related

how to create a batch file to execute command in Cmder?

I wanna create a batch file that launch Cmder and then execute some commands inside the Cmder. I know how to launch Cmder using a batch file but don't know, how to write/execute a command in Cmder using batch file.
I tries this...
#echo off
cd "C:\Program Files\cmder"
start Cmder.exe
cd "D:\Path"
Above code launches the Cmder.exe but doen't execute cd "D:\Path" inside Cmder.
You asked how to improve / fix
#echo off
cd "C:\Program Files\cmder"
start Cmder.exe
cd "D:\Path"
There are a few issues that could be better addressed in different ways. but as they appear not to be your real Issue I will simply suggest an alternative way to invoke cmder could be:-
#echo off
start "Cmder" "C:\Program Files\cmder.exe" /START "D:\Path"
I dont have a D drive so accept here my Path is e:\Path and the above command would result in the desired action, like so:-
In comments you explained that was not the intent but to run a cmd within cmder that would start first by changing the start directory.
What users need to acknowledge is that cmder is a very lightweight configuration wrapper around ConEmu and it is there that commands are processed as defaults or "Tasks"
So the request is to start up default Cmder and automatically change to e:\path where I can run further commands. One way to achieve this:-
Is to add my own MyAutoRun Task so I can invoke as
start "Cmder" "C:\Program Files\cmder.exe" /TASK MyAutoRun
Which is stored as a ConEmu Task like this:-
The full but limited range of Cmder arguments can be found at https://github.com/cmderdev/cmder#cmderexe-command-line-arguments
For configuring ConEmu tasks you need to see https://conemu.github.io/en/Tasks.html

Continue With CMD Commands After Batch Script

I am trying to write a batch script which, once complete, would allow the user to continue using the Windows command prompt as they normally would had no script been run. Is this possible? Thank you in advance for any help.
If you manually open CMD (the Command Prompt) and invoke the batch file by name, CMD will remain open for additional commands after the batch file completes. You cannot do this by double-clicking on the batch file, but if you create a shortcut to the batch file that runs CMD.EXE with the /K switch, you will run the batch file and then leave CMD running for additional commands. See CMD at SS64.

run exe with parameters silently from batch file

I want to execute an executable along with it's parameters from a Batch file silently without printing anything on the console from the executable and the executable shouldn't be executed from another console(it shouldn't open another command-prompt to execute). For that I tried with start command as following and couldn't execute it.
start "C:\myApp.exe -mode='a' -inputFilePath='%filePath%'" -i silent
Where %filePath% is a variable and -mode,-inputFilePath are the arguments to my executable.
Please correct me for anything wrong in above statement and help me out in this. Thanks!
From your batch file, just execute the following:
C:\myApp.exe -mode='a' -inputFilePath='%filePath%' >NUL
the >NUL redirects the output to nothing for that command.

Run a batch file from Task Scheduler is not working with a java command

Run a batch file from Task Scheduler is not working with a java command inside the .bat file. If I run the .bat file manually its working good.
Here is the simple .bat file I'm trying to schedule
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24;
set CMD= "%JAVA_HOME%\bin\java" -version
echo %CMD%
%CMD%
When you type batchfile.bat on the command line, you are telling cmd.exe to read the file and execute each line it finds in it. When you double-click on your batch file in explorer, it calls cmd.exe for you, after reading the file associations in the registry.
Task Manager is not so kind.
So for your task to work, schedule it like this (from memory, not on a Windows box right now) :
cmd /c "c:\full\path\to\your\batchfile.bat"
For extra robustness, you could make sure you batch file run from a known directory, like the one that it reside in, by adding this at the top:
pushd %~dp0
REM .... The original batch file goes here ....
popd
And finally you could disable CMD autorun entry by adding /d right after cmd like this:
cmd /d /c "c:\full\path\to\your\batchfile.bat"
If ixe013's suggestion doesnt work go to
'Actions'
'Edit' the task
'Start in (optional):' Put the path to the directory where the script is
So for the last one if you have 'C:\Users\Desktop\script.py' just put in 'C:\Users\Desktop\' in the 'Start in (optional):' field
What worked for me was running the task as "Users" ( computername\Users ). Once I did that, and "run with highest privileges" checked, it ran without a hitch.
Giving the full path of java.exe in the batch file fixed it for me. In a notepad, I typed the following line:
"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" -jar "C:\Users\usernameXXXX\Documents\NetBeansProjects\JavaApplication5\dist\JavaApplication5.jar"
Save this as a app1.bat file (C:\temp\app1.bat)
In the Actions tab of the task scheduler, give the path to the batch file, i.e, C:\temp\app1.bat
Also, be careful in the Conditions tab of task scheduler- make sure you uncheck "Start the task only if the computer is on AC power"
All other ways did not work for me, I followed this guide:
http://richardstk.com/2012/06/15/scheduled-task-to-run-a-batch-file/#comment-6873
In order to get the batch file to run, I had to set the "Program\script" box to contain just the name of the script (ie. script.bat) and set the the folder path of the script in the "Start in (optional)" box
I gave full permission to user Everyone from security tab from Properties of the folder in which batch file is. and it started working.
What a coworker discovered on something he had that wasn't working, and I have verified on the system I had that wasn't working is the following:
When the whole task is initially setup, you HAVE TO initially use the radio button "Run only when user is logged on". It will ask for your password for the change.
Now run the task.
Verify that whatever the batch was supposed to do, did happen.
And THEN change to the radio button BACK TO 'Run whether user is logged on or not."
This solved a problem for both of us that we had individually been working on for hours.
Side notes: both issues were also trying to elicit a 3rd party FTP app (WinSCP and WinFTP respectively) in each of our cases. Regular "inhouse" batch/tasks were having no issues.
I had the same problem, and to solve it, I put the next command line into the batch file:
cd "CURRENT_DIRECTORY"
where CURRENT_DIRECTORY is the directory where the batch file is located.
Example:
Suppose i have my batch file named test.bat located into c:\windows\system32\mytest
in my test.bat file, i introduce the next command line:
cd c:\windows\system32\mytest

How to prevent batch file (.bat) from closing terminal when running commands?

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

Resources