I'm using the JCL Delphi library in my project. Below is my code.
// uses JclSysUtils;
var cmd := TJclCommandLineTool.Create(parts[0]);
if cmd.Execute(params) then
begin
...
end;
As you can see, I use TJclCommandLineTool
to invoke an external command line program. The problem is that the external program is always running in the current directory that I started my application. I want to know how can I pass a custom working directory to the external program. JCL's document is pretty lame and I can't find related information.
CodePudding user response:
TJclCommandLineTool does not have options like this. So easiest way to do it:
//uses System.IOUtil;
var oldDir := TDirectory.GetCurrentDirectory;
try
TDirectory.SetCurrentDirectory(ANewProgramDir);
var cmd := TJclCommandLineTool.Create(parts[0]);
if cmd.Execute(params) then
begin
// ...
end;
finally
TDirectory.SetCurrentDirectory(oldDir);
end;