Can't kill program by taskkill - batch-file

I use Tecplot to opem its script file (*mcr) to do visulization. After I write the batch codes to first open tecplot to launch the *mcr file and then kill it, I found the codes can't terminate the program. The codes in batch file is as following:
cd .\Re100\17\
cd .\0.001
tec360 extract.mcr
ping 192.0.2.2 -n 1 -w 100000
taskkill /F /IM tec360.exe
cd ..\
cd .\0.005
extract.mcr
ping 192.0.2.2 -n 1 -w 100000
taskkill /F /IM tec360.exe
But, if I manually closed the Tecplot then the batch file can work. Any help on this will be highly appreciated.

Try looking on this site http://technet.microsoft.com/en-us/library/bb491009.aspx It will show you how to use the task kill command.

You simply need to add a $!QUIT command in the end of your macro file "extract.mcr" that will close the tecplot after the macro has finished, this way your tecplot GUI will close itself. The macro file should look like this
#!MC 1410
# some other macro commands .....
$!QUIT
In my experience you don't really need the GUI of tecplot to load, you can run your macro in the batch mode which will be quick, and that won't require $!Quit command either. to run in batch mode your batch file look like this
cd .\Re100\17\0.001
tec360 -b extract.mcr
cd ..\0.005
tec360 -b extract.mcr
On an additional note, if you have same file name i.e. extract.mcr and a lot of folders where you want to run, then instead of hardcoding the bath like you did, in windows here is how it would be,
SET my_dir="Re100\17\0.001" "..\0.005"
FOR %%A IN (%my_dir%) DO (
cd %%A
tec360 -b extract.mcr
)
Now you can add as many folders in first line as you want with a space separating the paths for example
SET my_dir="path 1" "path_2" "path 3" "path 4"
and so on..

Related

many start commands batch in the same window

I would like to start 3 commands in the same window.
For now I have this batch but there are 3 different windows at each command.
start /d "c:\Program Files\myfolder" cmd /k cscript A
timeout /t 6 >nul
start /d "c:\Program Files\myfolder" cmd /k cscript B
timeout /t 6 >nul
start /wait /d "c:\PProgram Files\myfolder" cmd /k cscript C
What should I modify to have only one window? thanks
I think you can run a .bat file by changing the directory like so, cd C:\PATH\TO\DIRECTORY\WITH\FILE, then use call (file name here). This should work assuming that all the files are in the same directory, if not you'll just have to change the directory for each call method. If my code doesn't seem very helpful, check this page out https://superuser.com/a/1062322
Example Code
#echo off
cd PATH\TO\FILE\DIRECTORY
call FILE NAME
echo The file (file name here) has run!
pause
this code will make a call to the file and pause the terminal to keep it opened. You can take this code and make as many calls/cd's as you like. I hope this helped, If it doesn't work, please tell me what doesn't work and I'll try to fix it. Have a nice day :)

Unable to launch multiple programs via a batch file

Am trying to create a batch file, that would launch multiple programs. But unfortunately, things don't seem to work.
Kindly, find below my requirement:
Open InfluxDB server
Launch Grafana application.
Commands used in the batch:
#echo off
cd "C:\Users\C51539A\Downloads\influxdb-1.5.2-1"
Start.cmd
timeout 5
cd "C:\Users\C51539A\Downloads\grafana-5.1.3\bin"
grafana-server.exe
The above script, launches InfluxDB. But doesn't moves further.
Could you please suggest me, on how to proceed?
You need to use the call keyword to have control returned to the caller after invoking another batch script:
#echo off
cd "C:\Users\C51539A\Downloads\influxdb-1.5.2-1"
call start.cmd
...
Should start.cmd run InfluxDB synchronously (i.e. not in the background) you need to launch it in a separate window:
#echo off
cd "C:\Users\C51539A\Downloads\influxdb-1.5.2-1"
start "InfluxDB" cmd /c start.cmd
...
#echo off
cd "C:\Users\C51539A\Downloads\influxdb-1.5.2-1"
start InfluxDB
ping -n 6 127.0.0.1 > nul
cd "C:\Users\C51539A\Downloads\grafana-5.1.3\bin"
start grafana-server
Edit the "start InfluxDB" and "start grafana-server" to be the correct exe names, without .exe

Batch file - Output current cmd output to log?

I know > and >> redirect a command to a file, but how can I get every line of data from the batch file? I have many commands that echo stuff, but I want just 1 that will echo every single command that's been used in the window to a text document.
Batch file:
#echo off
Choice /n /c 12
If %errorlevel%==1 echo hi
Etc..
You know what works perfectly? Right click > edit > select all. HOW THE HELL DO I DO THAT IN CODE
Say your batch script is called myScript.bat, then redirect when you call it:
myScript >log.txt
You will want to add CALL if used from within another batch script.
You can do the redirection from within your script if you CALL a main routine:
#echo off
call :main >log.txt
exit /b
:main
rem rest of your code goes here.
You probably looking for the tee command. It allows for writing to both STDOUT and a textfile at the same time.
More info here : http://linux.101hacks.com/unix/tee-command-examples/

Batch file command not working

I am trying to run this batch file remotely It will kill the IE process's but when I try to open a .lnk file it won't do it. When I go onto that machine, open up the command prompt and type in the command to run the .lnk file it works with no issues.. please help!
Code to remotely execute batch file:
psexec -u Administrator -p password -i -d \\hostname "c:\Emergency_POD\test.bat"
Code on machine to run: (Only the taskill command works.. not the for command)
cd/
taskkill /im iexplore.exe /f
for %a in ("C:\Emergency_POD\*.lnk") do #start "" "%a"
Command to run on cmd (This command works with no issues:
for %a in ("C:\Emergency_POD\*.lnk") do #start "" "%a"
You'd probably be better off with %%a in place of %a in the batch file.

Closing Batch File

I wrote a batch file, which has 3 .bat file running in background. I have another batch file which has 3 .bat file, which is used to stop those .bat file which ran in first batch file. All this is working fine, but after stopping those .bat files, first batch file's command window is not closing. I gave 'exit' to both the batch file which I wrote.
Please help me in this.
You could try starting the other batch files with
CMD /C
alternatively when they are supposed to close, you could try closing them by name directly from the other batch file:
taskkill /F /IM batchname.bat
Are you using
call batchfile.bat
to run the batchfiles? If not, the flow will be unexpected.
if you could convert it to .exe, with Bat-To-Exe-Converter, you could use:
tskill [program]
Like if you want to close a batch file which is converted called 'helloworld.exe':
tskill helloworld
What you also could use,
is:
tskill cmd
And do this a few times. It will close 1 commdandprompt/time.
I do a delayed close with some of my batch scripts this way:
FOR /l %%a in (30,-1,1) do (TITLE %TITLE% -- Closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
EXIT /B 0

Resources