1

I want to generate "service-worker.js" using sw-precache

from command line (cmd.exe) I run this command and output is :

Total precache size is about 145 kB for 35 resources. service-worker.js has been generated with the service worker contents.

When I run this command from C# output is empty, here is my code:

Process proc = new Process
                    {
                        StartInfo = new ProcessStartInfo
                        {
                            FileName = @"cmd.exe",
                            Arguments = @"/c sw-precache",
                            UseShellExecute = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError = true,
                            CreateNoWindow = true,
                            WorkingDirectory = Path.GetFullPath(myDir)
                        }
                    };
proc.Start();
proc.WaitForExit();
string output = proc.StandardOutput.ReadToEnd();

If I run command like "dir" in Arguments = @"/c dir", output contains message from dir command,

what I do wrong?

Edit: In Console Application, output is returned normally, but not in Web Application

Alex
  • 8,908
  • 28
  • 103
  • 157
  • Why not run `sw-precache` directly? – Vilx- Oct 12 '17 at 13:27
  • @Vilx- I have to automate the process – Alex Oct 12 '17 at 13:32
  • what Vilx meant is setting the `FileName` to `sw-precache` and not using `cmd.exe` at all. – Behrooz Oct 12 '17 at 13:46
  • @Behrooz "FileName " => Gets or sets the application or document to start, it must to be a file, "sw-precache" is a command – Alex Oct 12 '17 at 14:17
  • 1
    I doubt that. There is no `sw-precache` command in cmd.exe, and AFAIK you can only add new "commands" by placing files in PATH or AppPaths. Try setting the `UseShellExecute` flag to `true` and `sw-precache` in the `FileName`. – Vilx- Oct 12 '17 at 15:47

1 Answers1

0

WaitForExit first then read the output. It stays after the process has exited.

Behrooz
  • 1,696
  • 2
  • 32
  • 54
  • Is your web application running in full trust or partial trust? I'm not a web developer so I can't be sure, but this could be it. – Behrooz Oct 12 '17 at 13:45
  • my web app has full control permissions, this is not the problem ( – Alex Oct 12 '17 at 13:57