cmd terminate application after specified time of execution - cmd

I installed linphone application and i am writing a bat file doing a loop through file to make calls through executing this command
echo call %%H%%Z#%%G^|"C:\Program Files (x86)\Linphone\bin\linphonec.exe"
Now the loop is working fine and everything is ok but the problem that linphone is not terminating after making the first command to move on for the remaining of the loop , when i try to use linphone directly thorough the cmd command it remain open until i use quit command like this
C:\Users\administrator>cd C:\Program Files (x86)\Linphone\bin
C:\Program Files (x86)\Linphone\bin>linphonec -s 111#1.1.1.1
WARNING: no real random source present!
Ready
Warning: video is disabled in linphonec, use -V or -C or -D to enable.
linphonec> Establishing call id to sip:111#1.1.1.1, assigned id 1
Contacting sip:111#1.1.1.1
linphonec> Call 1 to sip:111#1.1.1.1 in progress.
linphonec> quit
Terminating...
Call ended
linphonec> Call 1 with sip:111#1.1.1.1 ended (No error).
No response.
linphonec>
C:\Program Files (x86)\Linphone\bin>
how i can terminate the program in my command above after executing the call command ?

I have not linphone to test, but if the program accepts piped commands, maybe, this could work
(echo call %%H%%Z#%%G&echo quit)|"C:\Program Files (x86)\Linphone\bin\linphonec.exe"
edited to make it wait
(
echo call %%H%%Z#%%G
ping -n 11 localhost >nul 2>nul
echo quit
) | "C:\Program Files (x86)\Linphone\bin\linphonec.exe"
or
(echo call %%H%%Z#%%G& ping -n 11 localhost >nul 2>nul & echo quit)|"C:\Program Files (x86)\Linphone\bin\linphonec.exe"

Related

How to open teraterm SSH/Telnet connection from windows command prompt?

I got a solution to open a teraterm COM connection and run a macro -
"C:\Program Files (x86)\teraterm\ttermpro.exe" /I /C=7 /BAUD=115200 /M="E:\old data\Desktop\TTL\RvR\test.ttl"
However, need help on arguments to be given to open a SSH/Telnet connection to a particular host from cmd using teraterm and run a macro.
here is 100 percent working code for telnet to a remote host ip
send username password and a command on remote machine.
If you want to send any argument x as variable inside u can use VAR %x and %x% as its value
contents of test.ttl file in local folder as follows
start copy from next line by chanimg ip username and password
connect 'IP:23'
pause 2
sendln 'Remoteusername'
pause 2
sendln 'Remotepassword'
pause 2
logopen 'C:\Users\nocbb\test.txt' 0 0
sendln 'command on remote host'
pause 3
sendln 'logout'
logclose
end
copy till above line
Save as all files and test.ttl and
run in dos command
run using command
C:\Users\nocbb>"C:\Program Files (x86)"\teraterm\ttermpro /M=C:\Users\nocbb\test.ttl /nossh
Note Change the path as per installation folder of Teraterm in
ur installation of teraterm folder.

Writing pings to files batch

Im looking for the best way to write two instances of cmd ping commands to 2 seperate text files using a batch file.
Here is what I have but its not writing to the file im wondering why.
start cmd /k ping 8.8.8.8 -t >> c:\troubleshoot_connection_google.txt
start cmd /k ping 192.x.x.x -t >> c:\troubleshoot_connection_gateway.txt
Thanks for the help.
The problem with your commands, appart from the point that the root folder of the drive is usually not writteable, is when the redirection to the output file is done.
As you have it written, what is being redirected to the file is the output of the start command, but if you need to redirect the output of the ping command, the redirection must be part of the started command
start "" "cmd /c ping 8.8.8.8 -t >> c:\troubleshoot_connection_google.txt"

Having a batch file check its own output?

I'm wondering if it's possible to have a batch file check itself for a string.
I'm using a batch file to run Maven commands,and I want to check if anything failed by searching for a "FAILURE" string at the end of the script
I know you can FIND in other files, but can you have it check the current output on itself, or is the best solution to save the batch file output as a text and then search it?
As an example, if I had a batch file echo Hello World it would print Hello World, then I would want to search the output for Hello and tell me it found the string Hello.
I like vane's idea to take action upon the return code provided by mvn, but instead of using ERRORLEVEL, I like to use the || operator. The commands after || are only excecuted if the prior command failed.
::initialize error flag to undefined
set "mvnErr="
::run your Maven command and define the error flag if there was an error
call mvn {your arguments here} || set mvnErr=1
::You can now take action if there was an error
if defined mvnErr echo there was a Maven error
You can do this by checking the errorlevel after each Maven command. For example
#ECHO OFF
set hasErrors=0
REM execute maven command here
if not errorlevel 0 set hasErrors=1
REM more batch command and similar checking ...
if %hasErrors%==1 (
echo print your error info or do whatever
)
Building off of both the 2 previous answers, I think this gives the best of both worlds. The || syntax is short and easy to read and the IF statement before every command ensure processing only progresses when previous operations were successful.
set hasErrors=0
IF %hasErrors%==0 call mvn -f ./mycoservices/pom.xml install || set hasErrors=1
IF %hasErrors%==0 call mvn -f ./mycostatic/pom.xml install || set hasErrors=1
IF %hasErrors%==0 call mvn -f ./mycoweb/pom.xml install || set hasErrors=1
IF %hasErrors%==0 call mvn -f ./mycowebbundle/pom.xml install || set hasErrors=1
why not just exit the batch whenever it fail
if %ERRORLEVEL% NEQ 0 (
echo exit /b %errorlevel%
exit /b %errorlevel%
)

How do I run a slow running batch Asynchronously, specifically a SVN post-commit?

I have a slow running batch file that compiles a log of changes and then emails a user. I would like it not to cause the user's commits to perform slowly in TortoiseSVN.
#ECHO OFF
SET REPOS=%1
SET REV=%2
SET DIR=%REPOS%/hooks
SET PATH=%PATH%;%DIR%;C:\Utils
SET WORKING_COPY=C:\path\to\local\copy\
SET SITENAME=MySiteName
SET SMTP_SERVER=11.11.11.11
SET EMAIL_TO=my#email.email
SET EMAIL_FROM=my#email.email
SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS%
svn cleanup %WORKING_COPY%
svn update %WORKING_COPY%
ECHO The following changes were made to the code: > %DIR%/email.txt
ECHO. >> %DIR%/email.txt
svn log %WORKING_COPY% -v -r "%REV%" >> %DIR%/email.txt
svn diff %WORKING_COPY% -c "%REV%" --no-diff-deleted >> %DIR%/email.txt
sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt
I realised that this was running slowly, so I moved it to another file "email-changes.bat" and created a simple batch to call this batch asynchronously.
#ECHO OFF
#START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log
If I comment out the "START" line it runs and finishes instantly. If I remove the comment it takes forever to complete. I thought that should allow the post-commit to return to SVN quickly.
Is there any way I can get the code to not hang in Subversion, but still complete the emailing task in the background?
Try starting the real hook script in a separate process:
#ECHO OFF
cmd.exe /c START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log
if that doesn't work, find a tool that can start another bat file in a separate process/thread.

capturing error message from echo in cmd prompt

I'm writting out some text to a text file within a cmd batch script like such:
echo FlagValue=Y>>flag.txt
This normally works fine but occassionally if the text file is open by a different process, an error messgae is returned saying Access Denied. What I'd like to do is stop the batch file if an error occurs with something like:
if return_code GEQ 1 GOTO ERR
But can't find a return code from echo command. Does one exist, or is there a better tactic to use to capture error message?
echo FlagValue=Y>>flag.txt || echo access_denied Ensure you have rights
or
echo FlagValue=Y>>flag.txt
if /i %errorlevel% NEQ 0 do (
echo access_denied Ensure you have rights
call sendmail.cmd
)
Sample:
C:\Users\Me\Desktop>echo Hello > MyFile.txt || echo ERROR
Access is denied.
ERROR
C:\Users\Me\Desktop>echo Hello > a.txt || echo ERROR
C:\Users\Me\Desktop>
Everytime you run a command the ERRORLEVEL environment variable is set to your command's return. So try echo %ERRORLEVEL% straight after you run your command. (Be careful as any command you run inbetween (including echo) will override the %ERRORLEVEL%.
Also, check these out for more information:
Can a batch file capture the exit codes of the commands it is invoking?
Batch Files - Error Handling

Resources