Batch file console not stopping to display the output
Batch file console not stopping to display the output
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_datadata
@echo on
echo server started
pause
pg_ctl
@echo on
start "" /D"D:postgresql-9.6.0-1-windows-x64-binariespgsqlbin" "pg_ctl.exe" start -D "D:pg_datadata"
start "" "D:postgresql-9.6.0-1-windows-x64-binariespgsqlbinpg_ctl.exe" start -D "D:pg_datadata"
pg_ctl
.exe
start /?
1 Answer
1
I am assuming it is on the D: drive. use cd /d see cd /? for the reason why.
cd /d
cd /?
@echo off
cd /d "D:postgresql-9.6.0-1-windows-x64-binariespgsqlbin"
start "" "pg_ctl" start -D "D:pg_datadata"
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.
start "" /wait
The option
/wait does not result in halting batch file execution until pg_ctl is started, it halts batch file execution until pg_ctl has terminated itself. I don't know what pg_ctl really does. It perhaps is just a launcher like start and quickly terminates itself. In this case your description in last sentence is right. Otherwise the usage of /wait would not make much sense if pg_ctl runs for example as long as Windows is running once started.– Mofi
Aug 30 at 6:16
/wait
pg_ctl
pg_ctl
pg_ctl
start
/wait
pg_ctl
@Mofi Yes, that is what I mean. It is of no use to echo
service started if the startup process is still running, so we halt the batch file. That being said, it is still bad to assume the service has started, what if it failed, we still echo service started :)– Gerhard Barnard
Aug 30 at 6:21
service started
service started
It worked !!! Thank you very much. :)
– Adarsh Singh
Aug 30 at 6:35
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
In general it is always advisable to specify an application or script (batch file) to start with file extension and with full path. I don't know of which type
pg_ctlreally is because of missing file extension. I suggest to replace everything above@echo onbystart "" /D"D:postgresql-9.6.0-1-windows-x64-binariespgsqlbin" "pg_ctl.exe" start -D "D:pg_datadata"or bystart "" "D:postgresql-9.6.0-1-windows-x64-binariespgsqlbinpg_ctl.exe" start -D "D:pg_datadata"with assuming the file extension forpg_ctlis.exe. Run in a command prompt windowstart /?for its help.– Mofi
Aug 30 at 6:11