我一直在嘗試幾天(如果不是幾周...)以獲得下面的代碼工作。我試圖實現的是每天運行一個R腳本(通過Windows Server 2008 64位上的批處理腳本和Windows任務計劃程序)。 該R腳本將導航到某些網站,登錄並調用另存爲對話框以將完整頁面保存到特定路徑。AutoIt和RSelenium導航另存爲對話框(Firefox)
如果我在RStudio中的機器上運行我的腳本(Win 8 - 64bit),它就像一個charme - 遠程工作,而不是通過Rscript.exe。
問題似乎與SaveAs.au3腳本 - 當我通過RStudio或文件資源管理器調用它時,它可以很好地工作。的相同的R-腳本在批處理文件中執行與:
"C:\Program Files\R\R-3.2.3\bin\x64\Rscript.exe" "C:\JN\abc.R"
,直到系統()命令以及和crahses然後工作,而不會提供任何錯誤或警告。
也許有人有類似的問題,可以幫助嗎?謝謝!
3個的AutoIt腳本如下:
SaveAs.au3/EXE
ControlFocus("[CLASS:MozillaWindowClass]", "", "")
ControlSend("[CLASS:MozillaWindowClass]", "", "", "^s")
EditName.au3將來自R內可變地寫入,然後調用
KeyEnter.aut3
ControlFocus("Save as", "", "")
ControlClick("Save as","","[CLASS:Button; INSTANCE:1]")
將R腳本如下所示:
# compl is a vector of n href
if(length(compl) != 0) {
foreach(i=1:length(compl)) %do% {
server_check() # checks whether selenium driver is still active and firefox window is open
remDr$navigate(compl[i])
Sys.sleep(10)
login_check() # checks whether login is still active
Sys.sleep(5)
print(paste("attempt to save:",compl[i]))
system('C:\\JN\\SaveAs.exe') # does not matter whether .exe or .au3
Sys.sleep(3)
system("cmd", input = c('echo ControlSetText("Save as", "", "[CLASS:Edit; INSTANCE:1]", "") > C:\\JN\\EditName.au3',
paste0('echo ControlSend("Save as", "", "[CLASS:Edit; INSTANCE:1]", "',
gsub("/","_",gsub(website_url,"", compl[i])), ".htm",
'") >> C:\\JN\\EditName.au3')))
Sys.sleep(3)
system('C:\\"Program Files (x86)"\\AutoIt3\\AutoIt3.exe C:\\JN\\EditName.au3')
Sys.sleep(8)
system('C:\\"Program Files (x86)"\\AutoIt3\\AutoIt3.exe C:\\JN\\KeyEnter.au3')
Sys.sleep(30)
}
}
print("Complete save end")