0

Possible Duplicate:
Server.MapPath and running a command line utility from an ASP.NET application

Background:

I am trying to use this phantomjs tool to rasterize an SVG to PNG. It works when I manually run the EXE myself, but I can't make it work from a method in C#. I've even put breakpoints to make sure my path and arguments are correct.

The method starts by saving an SVG to file:///C:/SVG/ - it does this successfully. Then I try run the EXE which is located in my ASP.NET project (the .js file used by the tool is also there). If you check the link above, the EXE runs like this: phantomjs.exe rasterize.js [source] [destination]. So my source is the newly created SVG file, and my destination is a folder in the ASP.NET project - the same folder that the EXE is in. I'm guessing it's something to do with Server.MapPath or IIS permissions, but I'm stumped.

Here's the code:

// the EXE and the .js file are both located in 'ProjectRoot/Utilities/'
// filename is the newly created SVG file - 'whatever.svg'
string filepath = "C:/SVG/";
string serverPath = Server.MapPath("/Utilities/");
string args = " rasterize.js " + Path.Combine("file:///", filepath, filename) + " " + filename.Replace(".svg", ".png");
Process p = Process.Start(new ProcessStartInfo(serverPath + "phantomjs.exe", args));
p.WaitForExit(3000);

Running it doesn't throw an exception, it just fails to create the PNG file. When I debug and take the values and run the tool myself, it works fine. What can I do to narrow down the problem?

Community
  • 1
  • 1
notAnonymousAnymore
  • 2,637
  • 9
  • 49
  • 74
  • Is this running on the server or your local machine? – nick_w Oct 14 '12 at 09:58
  • Local machine, but I use IIS and point to 127.0.0.1. We are hosting once it goes live so I can configure IIS however I need to. – notAnonymousAnymore Oct 14 '12 at 10:02
  • It would be useful to know if the process is generating useful output that you can't see. See [here](http://stackoverflow.com/questions/285760/how-to-spawn-a-process-and-capture-its-stdout-in-net) for how to capture the output of a `Process`. – nick_w Oct 14 '12 at 10:06
  • Is it possible that the worker process doesn't have permission to write to the destination directory? – Brenda Bell Oct 14 '12 at 15:37
  • You should edit your old question instead of posting a very similar one with slightly changed details. – Patrick Oct 14 '12 at 16:15

1 Answers1

0

Differences between debug/release runs of the same code are generally caused by a race condition. In this case, the code which creates the SVG is probably not finished executing before your call to Process.Start, so nothing happens.

just.another.programmer
  • 8,579
  • 8
  • 51
  • 90