运行cmd程序需要路径

时间:2016-03-27 21:28:22

标签: windows cmd pascal lazarus

我正在使用Laarus编写一个简单的程序,我的答案类似于下面的代码。如何在特定目录中启动外部程序?

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;

1 个答案:

答案 0 :(得分:2)

在执行 .Execute 之前设置currentdirectory属性。 E.g。

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