Tyrrrz / CliWrap

Library for running command-line processes
MIT License
4.32k stars 264 forks source link

Cannot be used in IIS? #201

Closed MoondanceZ closed 1 year ago

MoondanceZ commented 1 year ago

Version

3.6.0

Details

I use it in my .net core api project like this

[HttpGet("CliWrapTest")]
public async Task<string> CliWrapTest()
{
    await Cli.Wrap("npm").WithArguments("install").WithWorkingDirectory(Path.Combine(AppContext.BaseDirectory, "Client")).ExecuteAsync();

    return "success";
}

while dubug, it run well. while publish to IIS, it have not been running correctly.

the error is:

Command execution failed because the underlying process (npm.cmd#12044) returned a non-zero exit code (-4048).

Command:
npm install

You can suppress this validation by calling `WithValidation(CommandResultValidation.None)` on the command.

Steps to reproduce

just a simple api project publish to iis

Tyrrrz commented 1 year ago

I doubt it has anything to do with IIS specifically. Run it with ExecuteBufferedAsync() to capture the stderr and see what the error was.

MoondanceZ commented 1 year ago

I create a new project, get a new exception, 😂😂

Failed to start a process with file path 'npm'. Target file or working directory doesn't exist, or the provided credentials are invalid. 

this problem may be is a little like this question https://stackoverflow.com/questions/54335270/failed-to-start-npm-when-published-to-iis but it didn't solve my problem

Tyrrrz commented 1 year ago

What happens if you run where npm in the command shell?

MoondanceZ commented 1 year ago

it's like this

C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd

It also cannot run properly in IIS.

Command execution failed because the underlying process (where.exe#564) returned a non-zero exit code (1).
Tyrrrz commented 1 year ago

Hmm that's really interesting. Maybe the IIS user has some restrictions? I assume you wouldn't be able to run via the Process class either, so maybe there's a more general StackOverflow topic somewhere related to this.

Tyrrrz commented 1 year ago

It's also possible that the IIS user (which is impersonated for launching services inside it) may have a different environment, where npm is not on PATH or somehow not available altogether.