iT邦幫忙

0

目錄下迴圈 每個子目錄 執行.bat Error while connecting to host (已解決)

格式如下
D:\Test(每個group命名不同)\target+(編號)\ (目標位置執行)
\target+(編號)\ (目標位置執行)
\target+(編號)\ (目標位置執行)

執行檔資料夾C:\script\A.bat
請問是否能在每個target+(編號)下都執行一次 A.bat, 或是複製到目錄下執行最後清除目錄下A.bat呢?
target數量會因group而變動有多有少

原先用matlab語言執行成功複製到目錄中並使用 [s,e]=dos('A.bat &'); 執行
會出現以下錯誤:
Error while connecting to host, No connection could be made because the target machine actively refused it. (10061)
Connect on sock (host=User, port=8676) failed, exhaused all end points
Unable to connect to 'User:8676',
sock error: Error = -1

但是手動點取資料夾中的.bat 就可以成功運行沒有跳出錯誤

.bat檔最前端為 cms 請問是因為程式權限問題而沒有辦法執行嗎?內部有應用到 Microsoft MPI 以及mpi4py不知道是否影響

對.bat內容較不了解還請各位大大賜教

更新:問題已解決,內部環境變數應用相同程式環境下會運用到bin/win64/mpiexec.exe 將其改名或移出系統環境變數即可用[s,e]=dos('A.bat &'); 呼叫CMD視窗執行並在結束回傳值

咦......有mpi4py,那為何不用python來解決這個問題呢?
@japhenchen 大師您好, 因為原作者寫好.bat 跟參數執行檔引用程式設定問題,但不太懂.bat執行運作,嘗試bat寫法卡在當下目錄無法各個資料夾中執行,虛心求教路徑下目錄數量並逐步進入資料夾之方式
matlab以下嘗試
run_num=dir([workspace '\target_*']); %目錄下 target數量
for i =1:length(run_num) %執行數量迴圈
runpath=run_num(i,1).name; %得到該目錄名稱
cd(runpath); %前往目錄
nowpath=pwd;
copyfile([script_path,'\','A.bat'],nowpath); %執行檔資料夾複製至該路徑
[s,e]=dos('A.bat '); %.A.bat執行 但會有Error while connecting to host
delete 'A.bat';
cd ..;
end
感謝感謝
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答