2014-03-28 17 views
1

我的電腦的操作系統是WIN7如何在cmd中打開一個新shell,然後在新shell中運行腳本?

我想用一個bat文件,打開一個新的shell,然後在新殼

這個殼是OSGeo4W殼牌

它位於運行腳本「 C:\ Program Files文件\ QGIS杜福爾\ 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殼牌

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

回答

0

你可以試試這個:

start cmd /K echo Hello world! 

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

你可以試試這個,如果你不想讓命令提示符保持:

start cmd /C echo Hello world! 
+0

謝謝但我在OSGeo4W.bat下有很多代碼 我想把代碼放在OSGeo4W中(它是一個shell) – Seventysecond

+0

OSGeo4W是一個基於linux的shell。 我試着用「啓動OSGeo4W.bat/k echo hello world」。出現'/ k'不是內部或外部命令。 – Seventysecond

0

恐怕我還沒有使用OSGeo4W我只是認爲這是使用的窗口。無論如何,我將列出一些在Linux上運行的選項,具體取決於shell,後面跟着一個使用Cygwin的例子。也許這將幫助..

- >您可以使用GNOME終端 Gnome終端是終端仿真應用程序和-X指定要執行下面的命令:

gnome-terminal -x ./script.sh 

- >後臺進程在當前終端中 您可以通過在命令行中添加與號(&)或在運行時按Ctrl + Z來背景第一個進程。然後輸入「bg」讓過程繼續。

- >您可以使用xterm和後臺進程:

xterm -e ./myProcess3 & 

- 使用cygwin的

cygstart /bin/bash -li 

希望我得到了所有正確>的例子,其實我無法測試它的權利現在(新窗口生成PC)。

-2

這是一個很好的問題。我也試圖做到這一點。您可以嘗試將其他腳本放在另一個.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 
0

我有類似的問題,我想辦法解決這樣的:我有不同的Python和OGR一個名爲script.bat腳本文件功能。在單獨的bat文件中,我鍵入:

call "C:\Program Files\QGIS 2.14\OSGeo4w.bat" start cmd.exe /k script 
pause 

此bat文件調用OSGeo4W Shell中的inital script.bat。

* note1:兩個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 

和兩個蝙蝠文件必須在目錄中的數據(C:\用戶\託尼\下載\ 11 \ computingArea)。我希望這會起作用,它對我有用!