2

I got the problem that use C# process to call the LibreOffic to shift the file to ODF series. When I am in Local everything is work, but I release my project to IIS. The web site just keep running forever. Could anyone can hlep to fix this issue?

My environment: Server OS:win Server2012 IIS: version 8.0.9200.16384 I tried these LibreOffice version(Nothing is work): Fresh version(stable) 5.4.3 Stable version 5.3.7 Carry version 5.4.2.2

I think The problem is some software not Compatible. I can see the task manager has the LibreOffic.exe running

My website keep running picture can see the LibreOffice running in task manager

public class OfficeConverter
{
    /// <summary>
    /// LibreOffice通用型轉檔功能
    /// </summary>
    /// <param name="inputFilePath">The input.</param>
    /// <returns>Data為轉檔後之路徑</returns>
    [STAThread]
    public static string ConvertDocument(string inputFilePath)
    {
        // 取得副檔名對應的參數
        string extensionParameter = ConvertExtensionToArg(Path.GetExtension(inputFilePath));

        //if (string.IsNullOrWhiteSpace(extensionParameter))
        //    throw new InvalidProgramException("Unknown file type for LibreOffice. File = " + inputFilePath);

        if (!File.Exists(inputFilePath))
        {
            throw new ArgumentException(string.Format("找不到檔案:{0}!", inputFilePath), nameof(inputFilePath));
        }

        string outputDir = Path.GetDirectoryName(inputFilePath) + @"\";
        string outputFileName = Path.GetFileNameWithoutExtension(inputFilePath);
        string outputPath = string.Empty;

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;

        // 設定執行檔路徑
        startInfo.FileName = ConfigurationManager.AppSettings["LibreOfficeExePath"];
        startInfo.WorkingDirectory = outputDir;
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        startInfo.Arguments = string.Format(" -headless -convert-to {1} {0}", inputFilePath, extensionParameter);

        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
        string[] ext = extensionParameter.Split(':');

        outputPath = Path.Combine(outputDir, outputFileName + "." + ext[0]);

        return outputPath;
    }

    /// <summary>
    /// 依據副檔名轉換成相對應的參數
    /// </summary>
    /// <param name="inputExtension"></param>
    /// <param name="outputExtensionType"></param>
    /// <returns></returns>
    private static string ConvertExtensionToArg(string inputExtension)
    {
        switch (inputExtension)
        {
            case ".doc":
            case ".docx":           
                return "odt:writer8";
            case ".xls":
            case ".xlsx":
            case ".xlsb":               
                return "ods:calc8";
            case ".ppt":
            case ".pptx":               
                return "odp:impress8";
            default:
                return null;
        }
    }

}

I modify my code to catch Process StandardError message. But I can't catch anything. The website just still running. my BackUpLog.txt doesn't have any new message. I think that Porcess.Start() then never return any response.

This is my code I modified

Leon Huang
  • 103
  • 11
  • You haven't provided any code? How do you expect us to troubleshoot it without the code? Please [read this](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). When showing code to launch Libre Office I expect to see something like [this](https://stackoverflow.com/a/46707962/495455) – Jeremy Thompson Dec 15 '17 at 02:26
  • Try to capture the output of the process to see if it's spouting any error messages https://stackoverflow.com/a/285841/1411687 – Alex Wiese Dec 15 '17 at 02:45
  • @JeremyThompson I added my code thanks. But I have one experience to release my project to another Server and it work. Using portable version. But in this server every version doesn't work. My website just keep running. I think LibreOffice doesn't give complete response to my project. But I can see the task manager has LibreOffice.exe running. – Leon Huang Dec 15 '17 at 02:46
  • What are the results if you run the LibreOffice command on the server manually? – Jeremy Thompson Dec 15 '17 at 02:57
  • Using Manual is work.Not use my program to run LibreOffice everything is work. – Leon Huang Dec 15 '17 at 03:14
  • @AlexWiese How cam I catch error massage in this code? exe just running nothing error screen(error yellow page)... – Leon Huang Dec 15 '17 at 04:01
  • @LeonHuang: you should capture the errorOutput stream of the process to see if you are receiving messages from the LibreOffice process. Probably the standardOutput as well. – Ignacio Soler Garcia Dec 15 '17 at 08:10
  • @IgnacioSolerGarcia I can't catch anything. Please check my code. The process doesn't return any message. – Leon Huang Dec 18 '17 at 03:34
  • @LeonHuang: do the same with standardOutput, developers sometimes do not redirect to the appropiate ouput. – Ignacio Soler Garcia Dec 18 '17 at 08:16
  • @IgnacioSolerGarcia still the same no any message(use StandardOutput). I think when the process start then never return... – Leon Huang Dec 18 '17 at 08:29
  • @LeonHuang: can't help anymore, sorry. I always do this kind of things with Office. – Ignacio Soler Garcia Dec 18 '17 at 10:57
  • @IgnacioSolerGarcia: It's ok. Thanks for your reply and patient. I really appreciate. – Leon Huang Dec 19 '17 at 08:54

0 Answers0