Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter with spaces and quotes fails to execute #107

Open
tomasr78 opened this issue Jan 25, 2024 · 1 comment
Open

Parameter with spaces and quotes fails to execute #107

tomasr78 opened this issue Jan 25, 2024 · 1 comment

Comments

@tomasr78
Copy link

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\\"
        };
@tomasr78 tomasr78 changed the title Parameters with spaces and quotes fails to execute Parameter with spaces and quotes fails to execute Jan 25, 2024
@Bartleby2718
Copy link

Bartleby2718 commented Feb 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants