i have a simple batch script for GRADLE android as below
#ECHO ON
set DIR=path
set APP=%DIR%\app1
cd %APP%
./gradlew assembleDebug
next i want to check when Gradlew build is done, i can continue next command
something like
if(./gradlew assembleDebug) then echo "pass"
else echo "failed"
but i don't know how to implement in batch script
anyone know please tell me how to implement
thanks
Related
I am currently creating an improvised installer for a cople software packages. To do this I have to install a couple MSI packages first before doing a couple file operations.
To install an MSI package I am using the following command:
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
This command works and installs the package instantly and witout any problems via CMD.
But when I put this command in my batch file and execute it as an administrator, I get the following error:
This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package
What cold be the problem? Using the same command via the console works flawlessly, only the batch file throws the error...
EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either. Full command in batch file:
start /wait msiexec /qn /a "Myinstaller V2.1.msi"
EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator
When I open a console with administrative rights and start my batch file it works for some reason...
Is there a way to make it work with the Right click > Run as administrator method?
SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator. With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause
I've now also implemented a feature to detect wether or not the installation fails or not:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause
The current directory changes when you run as administrator. If you want to prove that to yourself, see this post
Difference between "%~dp0" and ".\"?
Include the full path to your filename and it will work.
I want to build my app with custom run script.
After 'activator stage' I get built app, with default run script.
So I need to replace default script with my own.
I need batch file like this:
#echo off
set "name=projectName"
activator clean stage || pause 1
del ".\target\universal\stage\bin\%name%.bat"
exit
But after calling 'activator clean stage' script automatically close, how can I solve this problem?
If you are using Windows then bat:
#echo off
activator clean stage
copy custom.bat c:\target\universal\stage\bin\myproject.bat
Where custom.bat is your bat that will be used for start the project.
But better look at custom configuration of your project
https://www.playframework.com/documentation/2.1.x/ProductionConfiguration
I try to create a windows batch script that install nodeJs, express and bower, but for now doesn't work and I cant know what is the problem because the terminal closed after some seconds.
If I run all the instructions of the batch script one by one into a CMD all work OK.
How can I validate that every process was executed successfully? I mean if the install of express fail, get a message like "fail express framework install"
I think that the problem is the script doesn't wait finished install the fisrt block of code when try to install the next block.
Any idea for resolve?
This is my script:
::Windows Batch Script for Install nodeJs, express framework for nodeJs, bower and Ionic
#setlocal
#echo off
:: Install nodeJs & NPM
echo Instalando NodeJs ^& NPM (Node Package Manager)...
echo.
start /wait msiexec /i C:\EMWA\installers\node.msi /passive /norestart
::Install express framework
echo Instalando express framework nodejs
echo.
npm install express-generator -g
:: Install bower
echo Install bower
echo.
npm install -g bower
:: create a test project
IF NOT EXIST C:\EMWA\projects
mkdir C:\EMWA\projects
IF NOT EXIST C:\EMWA\projects\emwa_test
mkdir C:\EMWA\projects\emwa_test
pause > null
This is the purpose of the ERRORLEVEL keyword in the IF statement. See IF /? for details:
C:\...>if /?
Performs conditional processing in batch programs.
IF [NOT] ERRORLEVEL number command
....
NOT Specifies that Windows should carry out
the command only if the condition is false.
ERRORLEVEL number Specifies a true condition if the last program run
returned an exit code equal to or greater than the number
specified.
....
%ERRORLEVEL% will expand into a string representation of
the current value of ERRORLEVEL, provided that there is not already
an environment variable with the name ERRORLEVEL, in which case you
will get its value instead. After running a program, the following
illustrates ERRORLEVEL use:
goto answer%ERRORLEVEL%
:answer0
echo Program had return code 0
:answer1
echo Program had return code 1
You can also use numerical comparisons above:
IF %ERRORLEVEL% LEQ 1 goto okay
....
C:\...>
This works as long as the commands set an exit status, which many do.
I have created a python script that I would like to run every time I start my computer.
So I started creating a batch file that could later be put into my startup folder.
I tried this:
#echo off
start "C:\Users..........." (I gave the exact path)
and when I run it you can see the python script pop up for a moment, but then shuts down. What am I doing wrong?
this works here:
#echo off
start /b "" "%ProgramFiles%\Python33\python.exe" "%UserProfile%\Test.py" "more parameters"
pause
I need to figure out this seemingly very simple issue on windows .bat file. I have been using Linux for past 10 years full-time, so I am in pretty unfamiliar territory when it comes to .bat scripts.
We have some units tests that need to run on from this .bat file, and a build needs to be generated after the tests have run.
The bat file itself is very simple, I was thinking of just chaining the commands:
cls
echo "Running test suite - CRMSync"
echo
echo
REM from command: --static-backup
phpunit --bootstrap test/bootstrap_test.php --verbose --log-junit
echo "Running phploc for CRMSync"
phploc --count-tests --verbose > C:\CRMsync\testResults\phploc\index.html
echo "Executing phing"
phing
Now, simple enough except nothing is executed past phpunit command. How do I deal with this?
The unit tests run fine, but I am suspecting it could even be in the unit test lib that process is killed. Is there a way to fork the process somehow or get the other commands below to run?
Thanks SO'ers, as always, any help greatly appreciated.
I had the same problem for a development script that I made. And I tried all given solutions without being successful. At the end, I did it with cmd /C.
From the windows docs it will:
Run Command and then terminate
So for example, you can use it as follows:
cls
echo "Running test suite - CRMSync"
echo
echo
REM from command: --static-backup
cmd /C phpunit --bootstrap test/bootstrap_test.php --verbose --log-junit
echo "Running phploc for CRMSync"
cmd /C phploc --count-tests --verbose > C:\CRMsync\testResults\phploc\index.html
echo "Executing phing"
cmd /C phing
I hope you find this useful.
Similar to the post ujifgc, I use "start /b ..." in these situations. If you encapsulate the call to phpunit in another batch file, you can use "call".
Is phpunit itself a batch file (I don't do much PHP, so am not familiar with the tool)? If so, try using:
call phpunit --bootstrap test/bootstrap_test.php --verbose --log-junit
Try start /WAIT phpunit ... to fork process and wait for it or just start phpunit ... to fork and continue. Help is here: start /?
I used
start /b code .
cmd /k ng serve --build-optimizer --aot
to start Visual Studio Code and then a node js server.
But the Command line glitched with the % update text and more.
I then used
cmd /C code .
cmd /k ng serve --build-optimizer --aot
and the glitching stopped for the server progress update.