madelson/MedallionShell

Parameter with spaces and quotes fails to execute

Opened this issue · 1 comments

I need to execute an obscure LibreOffice command line from C#. It works fine from the command line, but it always fails when using Medallion.Shell with the parameter '--convert-to' and value 'csv:"Text - txt - csv (StarCalc)":44,34,76,1,-1'.

"C:\Program Files\LibreOffice\program\soffice.exe" --convert-to csv:"Text - txt - csv (StarCalc)":44,34,76,1,-1 C:\test.xlsx --outdir C:\_temp\

Medallion.Shell code is below but failing.

    var command = @"C:\Program Files\LibreOffice\program\soffice.exe";
    var args = new[]
    {
        "--convert-to",
        "csv:\"Text - txt - csv (StarCalc)\":44,34,76,1,-1",
        "C:\\test.xlsx",
        "--outdir",
        "C:\\_temp\\"
    };

    var result = Command.Run(command, args);  //runs the command
    result.Wait();

If I remove :"Text - txt - csv (StarCalc)":44,34,76,1,-1 it works, but I need those parameters.

        var command = @"C:\Program Files\LibreOffice\program\soffice.exe";
        var args = new[]
        {
            "--convert-to",
            "csv",
            "C:\\test.xlsx",
            "--outdir",
            "C:\\_temp\\"
        };

Context seems to be in https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html. It says the command should look like soffice --convert-to OutputFileExtension[:OutputFilterName[:OutputFilterParams[,param]]] [--outdir output_dir], and it includes examples like

--convert-to "html:XHTML Writer File:UTF8" *.doc
--convert-to "txt:Text (encoded):UTF8" *.doc

It's worth noting that the entire argument to --convert-to is wrapped in double quotes in both examples, not just the filter. You seem to have placed the double quotes in wrong places.
(Text - txt - csv (StarCalc) is also mentioned in that page as the filter name used in the APIs for Text CSV.)

@tomasr78

  1. Could you try placing the double quotes in different places? In this case, I guess it would be:
var command = @"C:\Program Files\LibreOffice\program\soffice.exe"; var args = new[]
{
    "--convert-to", "\"csv:Text - txt - csv (StarCalc):44,34,76,1,-1\"",
    "C:\\test.xlsx",
    "--outdir",
    "C:\\_temp\\"
};
var result = Command.Run(command, args); //runs the command
result.Wait();
  1. Have you tried launching it from another command line prompt? If you do something like cmd /c ""C:\Program Files\LibreOffice\program\soffice.exe" --convert-to csv:"Text - txt - csv (StarCalc)":44,34,76,1,-1 C:\test.xlsx --outdir C:\_temp\" as in this thread, I think it'll also fail.