Batch file 如何在cmd中打开新shell,然后在新shell中运行脚本?
我的电脑的操作系统是win7 我想使用.bat文件打开一个新的shell,然后在新的shell中运行脚本 这个shell是OSGeo4W shell 它位于“C:\Program Files\QGIS Dufour\OSGeo4W.bat”中 所以我用Batch file 如何在cmd中打开新shell,然后在新shell中运行脚本?,batch-file,powershell,Batch File,Powershell,我的电脑的操作系统是win7 我想使用.bat文件打开一个新的shell,然后在新的shell中运行脚本 这个shell是OSGeo4W shell 它位于“C:\Program Files\QGIS Dufour\OSGeo4W.bat”中 所以我用 cd "C:\Program Files\QGIS Dufour\" OSGeo4W.bat cd "C:\Users\tony\Downloads\11\computingArea" ogr2ogr -f CSV my_csv Grid.db
cd "C:\Program Files\QGIS Dufour\"
OSGeo4W.bat
cd "C:\Users\tony\Downloads\11\computingArea"
ogr2ogr -f CSV my_csv Grid.dbf
ogr2ogr -f CSV csv Grid.dbf
addcenter.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/Grid.csv
copy Grid.shp my_dir
copy Grid.shx my_dir
rd my_csv /s /q
rd csv /s /q
ogr2ogr -clipsrc t.shp test.shp ./my_dir/Grid.shp
rd my_dir /s /q
ogr2ogr -f CSV wellcsv welllocation.dbf
ogr2ogr -f CSV csv test.dbf
computingArea.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/test.csv
rd csv /s /q
rd wellcsv /s /q
move test.shp my_dir
move test.shx my_dir
del test.dbf /q
但是,此脚本仅打开OSGeo4W Shell
请告诉我如何解决此问题。您可以尝试以下方法:
start cmd /K echo Hello world!
它肯定可以在windows XP上运行,/K运行指定的命令,但保留新的cmd提示符!希望它有用
如果不希望cmd提示符保持不变,可以尝试以下操作:
start cmd /C echo Hello world!
恐怕我没有使用OSGeo4W,我只是假设它使用的是windows。无论如何,我将列出一些在Linux上工作的选项,具体取决于shell,后面是一个使用Cygwin的示例。也许会有帮助 ->你可以使用gnome终端 Gnome terminal是一个终端仿真应用程序,-x指定要执行后续命令:
gnome-terminal -x ./script.sh
->当前终端中的后台进程
您可以通过在命令行中添加一个符号(&)或在命令行运行时按Ctrl+Z对第一个进程进行后台处理。然后输入“bg”以继续该过程
->您可以使用xterm和background来完成以下过程:
xterm -e ./myProcess3 &
->使用cygwin的示例
cygstart /bin/bash -li
希望我能做到这一点,实际上我现在无法测试它(新的windows build PC)。这是一个好问题。我也在尝试这样做。您可以尝试将脚本的其余部分放在另一个.bat文件或.sh文件中,并将此文件作为参数传递给OSGeo4W.bat。脚本如下所示:
cd "C:\Program Files\QGIS Dufour\"
OSGeo4W.bat script_inside_the_shell.bat
或
我遇到了类似的问题,我设法解决了这个问题:我有一个名为script.bat的脚本文件,其中包含各种python和ogr函数。我在单独的bat文件中键入:
call "C:\Program Files\QGIS 2.14\OSGeo4w.bat" start cmd.exe /k script
pause
此bat文件在OSGeo4W Shell中调用inital script.bat
*注1:两个bat文件必须位于同一目录中。
**注2:在您的情况下,script.bat将包含以下内容:
ogr2ogr -f CSV my_csv Grid.dbf
ogr2ogr -f CSV csv Grid.dbf
addcenter.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/Grid.csv
copy Grid.shp my_dir
copy Grid.shx my_dir
rd my_csv /s /q
rd csv /s /q
ogr2ogr -clipsrc t.shp test.shp ./my_dir/Grid.shp
rd my_dir /s /q
ogr2ogr -f CSV wellcsv welllocation.dbf
ogr2ogr -f CSV csv test.dbf
computingArea.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/test.csv
rd csv /s /q
rd wellcsv /s /q
move test.shp my_dir
move test.shx my_dir
del test.dbf /q
单独的bat文件将是:
call "C:\Program Files\QGIS Dufour\OSGeo4w.bat" start cmd.exe /k script
两个bat文件都必须位于包含数据的目录中(C:\Users\tony\Downloads\11\computingArea)。我希望这会起作用,它对我起作用了 谢谢,但是我在OSGeo4W下有很多代码。bat我想把代码放在OSGeo4W中(它是一个shell)OSGeo4W是一个基于linux的shell。我尝试使用“start OSGeo4W.bat/k echo hello world”,结果显示“/k”不是内部或外部命令。
call "C:\Program Files\QGIS Dufour\OSGeo4w.bat" start cmd.exe /k script