简体   繁体   中英

From a C# MVC controller action, is it possible to execute a gulp task

From a C# MVC controller action, is it possible to execute a gulp task and if so how would I go about doing this?

In my C# app, I'm trying to check if a given string (submitted in a form) is valid sass. There are a couple of C# CSS parsers but I can't find one that can handle sass (*.scss).

In my projects I use a gulp task that compiles sass and reports any errors so I was wondering if there was a way I could utilize this to do the validation in my C# app ie add the text input from my C# app to a .scss file, get the gulp task to try and compile it, if it passes without errors then I know the sass is valid.

Maybe I'm barking up the wrong tree here but any help would be much appreciated.

Ok. There's a few things here (in your question) that a scaring the absolute crap out of me but I think the easiest summary of it is this :-

Given an ASP.NET MVC Controller , how can I call -another- .exe process?

So assuming you still want to do this, ignoring security vun's and stuff (I'll just roll with you, here...) I think you need to run a new AppDomain and then in that app domain run your exe. If the exe fails, you can then capture the error message also.

Updated as per comments

Random code taken from first'ish google result :

 
 
 
  
  try { //Create a new appdoamin for execute my exe in a isolated way. AppDomain sandBox = AppDomain.CreateDomain("sandBox"); try { //Exe executing with arguments sandBox.ExecuteAssembly(".exe file name with path"); } finally { AppDomain.Unload(sandBox);//destry created appdomain and memory is released. } } catch (Exception ex)//Any exception that generate from executable can handle { //Logger.log(ex.Message); }
 
  

so here, you would run the gulp.exe and pass in your command line args, include the sass content (content saved to a file?).

Now, if the .exe isn't a .NET assembly, then you might need to use the Process method...

something like this.. (pseudo code)

Process app = new Process();
app.StartInfo.FileName = @"D:/Path to /My/Program to be run.exe";
app.Start();

Again - not testing, but this should be enough to get you started...

Do note -> running a Process requires serious security permissions on the server, so generally hosted servers (like Azure Websites Site etc) lock all this down to protected themselves. If you own the server, then go nuts.

Final Note:

  1. I've never seen or used Node.
  2. I've never seen or used gulp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM