簡體   English   中英

如何在cmd中打開一個新shell,然后在新shell中運行腳本?

[英]How to open a new shell in cmd,then run script in a new shell?

我的電腦的操作系統是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.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

請告訴我如何解決這個問題。

我有類似的問題,我設法解決這樣的問題:我有一個名為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。

* note1:兩個bat文件必須位於同一目錄中。 ** note2:在你的情況下,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)。 我希望這會奏效,對我有用!

你可以試試這個:

start cmd /K echo Hello world!

它肯定適用於Windows XP,/ K運行指定的命令,但保留新的cmd提示! 希望它有用!

如果您不希望保留cmd提示符,可以嘗試此操作:

start cmd /C echo Hello world!

我擔心我沒有使用OSGeo4W我只是假設它使用的是Windows。 無論我是否會列出一些適用於Linux的選項,具體取決於shell,然后是使用Cygwin的示例。 也許它會有所幫助..

- >你可以使用gnome-terminal Gnome-terminal是一個終端仿真應用程序,-x指定你想要執行后續命令:

gnome-terminal -x ./script.sh

- >當前終端中的后台進程您可以通過在命令行中添加&符號(或)或在運行時按Ctrl + Z來對第一個進程進行后台處理。 然后輸入“bg”讓該過程繼續。

- >你可以使用xterm和后台進程:

xterm -e ./myProcess3 &

- >使用cygwin的一個例子

cygstart /bin/bash -li

希望我做對了,我實際上現在無法測試它(新窗口構建PC)。

這是一個很好的問題。 我也試圖這樣做。 您可以嘗試將其余腳本放在另一個.bat文件或.sh文件中,並將此文件作為參數傳遞給OSGeo4W.bat。 腳本將是這樣的:

cd "C:\Program Files\QGIS Dufour\"  
OSGeo4W.bat script_inside_the_shell.bat

要么

cd "C:\Program Files\QGIS Dufour\"  
OSGeo4W.bat sh script_inside_the_shell.sh

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM