[英]Running Commands in Batch FIle
I am trying to create a batch file to run start some micro services and database 我正在尝试创建一个批处理文件以运行以启动一些微服务和数据库
1 FOR /F "tokens=4 delims= " %%P IN ('netstat -a -n -o ^| findstr :1000') DO @ECHO TaskKill.exe /PID %%P
2 FOR /F "tokens=4 delims= " %%P IN ('netstat -a -n -o ^| findstr :1001') DO @ECHO TaskKill.exe /PID %%P
3 FOR /F "tokens=4 delims= " %%P IN ('netstat -a -n -o ^| findstr :5432') DO @ECHO TaskKill.exe /PID %%P
4 start cd "C:\Program Files\PostgreSQL\10\bin\" & pg_ctl.exe -D "c:\Program Files\PostgreSQL\10\data" start
@REM to start service
5 start javaw -jar -Dserver.port=1000 text-annotation-tool-1.0-SNAPSHOT.jar
Line 1 to 3 and Line 5 execute correctly when executed by commenting line 4. 第1至3行和第5行在注释第4行时正确执行。
Line 4 is to start a Postgres server in a new prompt (beacuse of the Dir change). 第4行是在新的提示下启动Postgres服务器(由于目录更改)。 I think the problem is with the way I have used quotes.
我认为问题出在我使用引号的方式上。 The 'start' at the beginning and ending of line 4 serve different purpose.
第4行开始和结束处的“开始”有不同的用途。
Also, if I execute line 4 in different prompt, How do I close the prompt after execution (nohup equivalent) 另外,如果我在不同的提示下执行第4行,如何在执行后关闭提示(等效于nohup)
There are two errors: You can't "pass" cd
to the start command. 有两个错误:您不能将
cd
“传递”到启动命令。 And start
has the quirk to interpret the first quoted parameter as the new window's title. 并且
start
具有将第一个引用的参数解释为新窗口标题的怪癖。 So start "C:\\Program Files\\PostgreSQL\\10\\bin\\" ...
wouldn't work, you need to supply a dummy window title. 因此,
start "C:\\Program Files\\PostgreSQL\\10\\bin\\" ...
将不起作用,您需要提供一个虚拟窗口标题。 The &
also seems wrong &
也似乎是错误的
So you need: 因此,您需要:
start "Postgres Server" "C:\Program Files\PostgreSQL\10\bin\pg_ctl.exe" -D "c:\Program Files\PostgreSQL\10\data" start
As the full path to pg_ctl.exe
is supplied, there is no need for a cd
. 由于提供了
pg_ctl.exe
的完整路径,因此不需要cd
。 But if you want to define the default directory for the new process, you have to use the /D
parameter: 但是,如果要为新进程定义默认目录,则必须使用
/D
参数:
start "Postgres Server" /D "C:\Program Files\PostgreSQL\10\bin" pg_ctl.exe -D "c:\Program Files\PostgreSQL\10\data" start
Unrelated, but: putting the Postgres data directory into c:\\Program Files\\
is a very bad idea. 无关,但是:将Postgres数据目录放入
c:\\Program Files\\
是一个非常糟糕的主意。 That directory has special permissions for a purpose. 该目录具有特定用途的特殊权限。 You should use
%ProgramData%
or %AppData%
instead 您应该改用
%ProgramData%
或%AppData%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.