Batch file console not stopping to display the output - batch-file

I'm trying to execute a batch file but its console is not stopping for its output.
here's the code:
goto D:
cd postgresql-9.6.0-1-windows-x64-binaries
cd pgsql
cd bin
start pg_ctl start -D D:\pg_data\data
#echo on
echo server started
pause

I am assuming it is on the D: drive. use cd /d see cd /? for the reason why.
#echo off
cd /d "D:\postgresql-9.6.0-1-windows-x64-binaries\pgsql\bin"
start "" "pg_ctl" start -D "D:\pg_data\data"
echo server started
pause
change to start "" /wait if you want to wait for the service to start before you echo it has been started.

Related

Jenkins Pipeline Batch file output

I have a multiline batch script in one of my steps that kicks off a build process. Problem is, the jom.exe creates another shell prompt where you don't see any of the output of in real-time on Jenkins. Is there a way to redirect output? Here is the snippet of the area in question:
stage('Build') {
steps {
bat """
echo ${BUILD_DIR}
call "${VCVARSALL}\\vcvars64.bat"
IF EXIST "%BUILD_DIR%" (
rmdir "%BUILD_DIR%" /s /q
)
mkdir "%BUILD_DIR%"
cd "%BUILD_DIR%"
start "" /WAIT "${QT_HOME}\\qmake.exe" ..\\FFF.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug"
start "" /WAIT "${JOM_HOME}\\jom.exe" -j 8 -f Makefile.Debug"
"""
}
}
Thanks to the comments I managed to fix this by removing the random quote and removing the start "" /WAIT

My batch file script to run coded UI test is not working

So I have a coded UI test that works fine. I've create a batch file script so that i can run in windows task scheduler. It keeps showing "Failed"
This is what I tried:
cd /
cd "C:\Users\alish\source\repos\CodedUITestProject6\CodedUITestProject6\obj\Debug\CodedUITestProject6.dll "
#echo off
set max=.set count=.
echo starting test execution
echo =======================
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\MSTest.exe" /testcontainer:C:\Users\alish\source\repos\CodedUITestProject6\CodedUITestProject6\obj\Debug\CodedUITestProject6.dll/test:CodedUITestMethod1
echo all done
#exit
Not much sense in doing the cd / nor the need to cd to dir if you put it path anyway. Also I recall you need a space before /test: So just do:
#echo off
set max=. && set count=.
cd /d "%userprofile%\source\repos\CodedUITestProject6\CodedUITestProject6\obj\Debug\"
echo starting test execution
echo =======================
Start "" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\MSTest.exe" /testcontainer:CodedUITestProject6.dll /test:CodedUITestMethod1
echo all done
pause

How to create a batch file that starts an executable with parameters

I am trying to create a batch file that opens a RethinkDB database.I need to execute it like this
rethinkdb.exe -http-port <portno>
How can i do this from a batch file?I just wanted to start the script.The port will be hard-coded in the script.
I tried:
#echo off
cd /d "C:\Users\username\Desktop\personal\wsrethink"
start "" rethinkdb /path:"C:\Users\username\Desktop\personal\wsrethink\rethinkdb.exe" --http-port 9300
timeout 10
pause
Try this
#echo off
start "" /D "C:\Users\username\Desktop\personal\wsrethink" rethinkdb.exe --http-port 9300
timeout 10
pause

Jboss 7 automatic deployment of EAR bat file

I am trying to automate my maven build and deployment process of the EAR in Jboss. I managed to write a bat file for the same which is given below.
ECHO OFF
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
#echo | call C:\Work\jboss-as-7.1.1.Final\bin\jboss-cli.bat --connect --controller=[my-machine-name]:9999 command=:shutdown
del /q C:\Work\jboss-as-7.1.1.Final\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
cd C:\Work\jboss-as-7.1.1.Final\bin
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\data" /s /q
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\log" /s /q
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\tmp" /s /q
standalone.bat -bmanagement [my-machine-name] -b [my-machine-name] -c standalone-full-ha.xml
{code for check of deployment success/failure}
PAUSE
Here you can see that I am using the line
standalone.bat -bmanagement sbstjwsvm1509 -b sbstjwsvm1509 -c standalone-full-ha.xml
My requirement is that I want to check if the EAR was deployed successfully from my bat file.One way which I thought of is to check for .deplyed or .failed extension files in the Jboss deployment folder.I tried to write codes for the same but my code which is written below the above mentioned line is not getting executed.Is there any other means by which I can achieve this?Or what am I doing wrong in my bat file?Why is my code to check for deployment not getting executed?
Because the standalone.bat isn't executing in background and will be running the JBoss instance until you kill/stop it (ctrl+C signal or like you shutdown through jboss CLI). See this answer to get examples and details about you want to achive.
Since you are using maven, I suggest you to use jboss-as-maven-plugin.
Take a look the Usages, you will find commands to deploy/undeploy applications, resources, and to start/stop the server.
Then you could integrate the plugin execution to stop/clean in the maven clean phase and deploy/start on maven install phase using goals. See complex examples.
Thought of posting my solution here.
ECHO OFF
SET "JBOSS_DIR=C:\Work\jboss-as-7.1.1.Final"
SET "deployedAPP=MyApp.ear"
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
#echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
del /q %JBOSS_DIR%\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
cd %JBOSS_DIR%\bin
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
SET count=0
:checkIfDeployed
if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.deployed" (
GOTO appDeployed
)
if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.failed" (
GOTO deployFailed
)
PING -n 6 -w 1 localhost >nul
GOTO checkIfDeployed
:appDeployed
PAUSE
EXIT
:deployFailed
SET /A count+=1
if %count% == 5 ( goto end )
#echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
GOTO checkIfDeployed
:end
PAUSE
Used the line
START CMD /C CALL MyJboss.bat
to start JBoss in another cmd window.Now all my codes from below will get executed.

I keep getting access denied or nothing at all

if I run this program it says Access denied and when I run it as adminastrator it does nothing its supposed copy directries and accounts to 2 .ini files:
#echo off
mode 1000
:start
cls
echo welcome to F_scan
echo do you want to scan
set /p yn=[Y/N]
if %yn%==y (
goto virus
) else (
exit
)
:virus
cls
dir/s >> config.ini
net user >> config.ini
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
dir/s >> altconfig.ini
exit
rem shutdown library
:shutdown
shutdown -s
goto shutdown
:restart
shutdown -r
goto restart
Your repetitive cd .. should brings you close to the root of the disk.
Probably, your not allowed to write there
You can try
...
net user >> config.ini
dir \ /s >> altconfig.ini
or dir ..\..\..\..\..\.. /s >> altconfig.ini
to write your altconfig.ini in the initial directory, where you're probably allowed to write.
In this case you're probably wanting to redirect output of the commands to a file in the directory of the batch-file itself, instead of where you're executing the commands. To do this, you can use:
dir/s >> "%~dp0config.ini"
%~dp0 is a variable that holds the location of the currently executed batch-file.

Resources