2016-03-27 70 views
0

我正在使用Laarus編寫一個簡單的程序我有我的代碼下面的答案類型。如何在特定目錄中啓動外部程序?運行cmd程序需要路徑

procedure TForm1.Button2Click(Sender: TObject); 
var 
F: File; 
i, filehandle: Integer; 
runprogram:TProcess; 
begin 
    runprogram :=Tprocess.create(nil); 
    runProgram.CommandLine:='C:\Users\stran\Downloads\123\dcars.exe'; 
    runProgram.Execute; 
    Runprogram.free; 
    //This works but I need to navigate their first for the program 
    //to pick up its cmd line preferances.ini file 
    //I need to or have the program startin C:\...\...\.. 
    //in cmd(prompt)cd C:\Users\stran\Downloads\123\ 
    //then dcars.exe and it picks up its ini file and runs 
end; 
+0

你有問題嗎? –

+0

如何將路徑傳遞給執行文件,如代碼提示中所述 – Data

+1

我想你需要設置.CurrentDirectory。 –

回答

2

你做.Execute之前設置currentdirectory財產。例如。

runprogram.currentdirectory:='C:\Users\stran\Downloads\123\';