I have Apache FOP in a folder on my desktop. I have a C#.NET application that takes a stylesheet and an xml-file and then should pass those as parameter to the command line, where they should then be processed by Apache FOP.

The command line opens, but nothing happens.

This is my code:

private void OpenCommandLine(string XSL_As_Param,string XML_As_Param)
{
    try
    {
        Textfield.AppendText("Transformation started\n");
        commandlineargs = @"fop -xml Stuff\\"+XML_As_Param+" -xsl Stuff\\"+XSL_As_Param+" -pdf output.pdf -c conf/fop.xconf";
        startInfo.FileName = "cmd.exe";
        startInfo.Arguments = commandlineargs;
        process.StartInfo = startInfo;
        process.Start();
    }
    catch (Exception e)
    {
        Textfield.AppendText(e.StackTrace);
        Textfield.AppendText(e.Message);
    }
    finally
    {
        Textfield.AppendText("\n\nTransformation done\n");
        process.Close();
    }
}

Plus, the commandline arguments are

"fop -xml Stuff\\\\Sicherheitshinweise.xml -xsl Stuff\\stylesheet.xsl -pdf output.pdf -c conf/fop.xconf"

Where do the "\\\\" and "\\" come from? Shouldnt they be escaped to just \ ? (I'm on Windows 7) XML_As_Param and XSL_As_Param have the correct values (just the filename plus extension)

Thanx for your help!

有帮助吗?

解决方案

I've got it:

private void OpenCommandLine(string XML_As_Param, string output)
{
    try
    {
        Textfeld1.AppendText("\n\nTransformation started\n");

        MyBatchFile = @"transform.bat";
        XML_filename = @"" + XML_As_Param + "";
        XSL_filename = @"stylesheet.xsl";
        this.output = @"" + output + "";

        process = new Process { StartInfo = { Arguments = string.Format("{0} {1} {2}", XML_filename, XSL_filename, output) } };
        process.StartInfo.FileName = MyBatchFile;
        process.Start();
    }
    catch (Exception e)
    {
        Textfeld1.AppendText(e.StackTrace);
        Textfeld1.AppendText("\n");
        Textfeld1.AppendText(e.Message);
    }
    finally
    {
        process.Close();
    }
}

And the batch file:

@echo off
cd pathfofop\FOP
fop -xml %1 -xsl ..\stylesheets\%2 -pdf %3.pdf -c conf\fop.xconf
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top