0

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!

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.