Any *effectively working* solution for calling an external Windows executable, with arguments, from inside Ada?
For example, the following command runs fine when given on the Windows command line:
"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" /f "C:\long path\with spaces\and accented letters\like in the words\declaração de autorização.docx" /mSave_As_Txt
The same command FAILS when called from inside Ada with any of the know "solutions" on GNAT gem [1] and Rosetta Code [2].
Any *effectively working* solution for calling an external Windows executable, with arguments, from inside Ada?
For example, the following command runs fine when given on the Windows command line:
"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" /f "C:\long path\with spaces\and accented letters\like in the words\declaração de autorização.docx" /mSave_As_Txt
The same command FAILS when called from inside Ada with any of the know "solutions" on GNAT gem [1] and Rosetta Code [2].
But there must be a way!
Share your good code.
Thanks all.
Yeah, it's probably the quotation marks. I found no way around it with GNAT.OS_Lib. The quotes are needed because the names have spaces.
Yeah, it's probably the quotation marks. I found no way around it with GNAT.OS_Lib. The quotes are needed because the names have spaces.
Only way I found that works is with the command inside a .BAT file, then call that with GNAT.OS_Lib.Spawn
Arguments : Argument_List :=
( 1=> new String'("C:\Test\save_as_txt.bat"),
2=> new String'("")
);
begin
Spawn
( Program_Name => "C:\Test\save_as_txt.bat",
Args => Arguments,
Output_File_Descriptor => Standout,
Return_Code => Result
);
Also the BAT file *must* start with the magic incantation
chcp 65001
on the first line, in order for the accented characters to work.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:17:14 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,953 |