4

I'm trying to uploading a file and then using server-side processes to convert it.

This is part of a Visual Studio Web ASP.NET web application running on a ASP.NET Development server, localhost:8638

string fn = System.IO.Path.GetFileNameWithoutExtension(File1.PostedFile.FileName);
Process p = new Process();
                    p.StartInfo.WorkingDirectory = Server.MapPath("/Data");
                    p.StartInfo.FileName = "cmd.exe";
                    p.StartInfo.Arguments = "soffice --headless --invisible -convert-to pdf "+fn+".ppt";
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.Start();
                    p.WaitForExit();

I can manually open cmd.exe inside of the Datadirectory, then type this command, substituting the file name, and it'll work. However, running this code does not produce any result

What am I missing, or doing wrong?

5
  • What goes wrong when you run this code? Commented Jun 18, 2013 at 16:49
  • It silently fails to convert the file to a .pdf Commented Jun 18, 2013 at 16:52
  • 4
    cmd.exe doesn't take arguments like that. You should run the process itself. Commented Jun 18, 2013 at 16:53
  • Is it running under a user account that has permissions? You could attach a debugger to the process and see what happens. Commented Jun 18, 2013 at 16:53
  • @PrestonGuillot Right, I'm never reading it. I could do what Oren suggests and read the output, but that has never given me any useful information Commented Jun 18, 2013 at 16:57

1 Answer 1

6

You can't just pass everything in to cmd. You need to use the /C parameter, which will open a command prompt with those commands and terminate it when it finishes running that command. Try changing your arguments to

StartInfo.Arguments = "/C soffice --headless --invisible -convert-to pdf "+fn+".ppt";

An alternate solution would be to simply run the process itself (as suggested in the comments by SLaks). Change p.StartInfo.FileName to the appropriate executable, edit your arguments, and you should be good to go. That should be the preferred method, as it does what you want more directly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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