<commit_before>### Run a .exe from asp.net web app

Run a .exe from a web applicaiton

A few important notes.
The App Pool user needs to be able to have access to the directory of the file location.
If the location is a network share, the full directory path needs to be used. `\\server\filename\yourexe.exe` Also the user would need access to the location as well.

```
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
    using (var process = new Process())
    {
        process.StartInfo.FileName = @"..\HelloWorld\bin\Debug\helloworld.exe"; // relative path. absolute path works too.
        process.StartInfo.Arguments = $"{id}"; //optional
        //process.StartInfo.FileName = @"cmd.exe";
        //process.StartInfo.Arguments = @"/c dir";      // print the current working directory information
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.UseShellExecute = false;

        //configure the Console output
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;

        process.OutputDataReceived += (sender, data) => Console.WriteLine(data.Data);
        process.ErrorDataReceived += (sender, data) => Console.WriteLine(data.Data);

        Console.WriteLine("starting");
        process.Start();
        process.BeginOutputReadLine();
        process.BeginErrorReadLine();
        var exited = process.WaitForExit(1000 * 10);     // (optional) wait up to 10 seconds
        Console.WriteLine($"exit {exited}");
    }
    return "value";
}
```

- Source(s)
  - [From](https://codeburst.io/run-an-external-executable-in-asp-net-core-5c2f8b6cacd9)
  - [2](link2)<commit_msg>Update run-exe-from-web.md<commit_after>### Run a .exe from asp.net web app

There is a couple options.

#### Option 1
- Run the exe on the server
- Run the exe on a network share

A few important notes.
- The App Pool user needs to be able to have access to the directory of the file location.
- If the location is a network share, the full directory path needs to be used. `\\server\filename\yourexe.exe` Also the user would need access to the location as well.

```
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
    using (var process = new Process())
    {
        process.StartInfo.FileName = @"..\HelloWorld\bin\Debug\helloworld.exe"; // relative path. absolute path works too.
        process.StartInfo.Arguments = $"{id}"; //optional
        //process.StartInfo.FileName = @"cmd.exe";
        //process.StartInfo.Arguments = @"/c dir";      // print the current working directory information
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.UseShellExecute = false;

        //configure the Console output
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;

        process.OutputDataReceived += (sender, data) => Console.WriteLine(data.Data);
        process.ErrorDataReceived += (sender, data) => Console.WriteLine(data.Data);

        Console.WriteLine("starting");
        process.Start();
        process.BeginOutputReadLine();
        process.BeginErrorReadLine();
        var exited = process.WaitForExit(1000 * 10);     // (optional) wait up to 10 seconds
        Console.WriteLine($"exit {exited}");
    }
    return "value";
}
```

#### Option 2
- Run an exe on client pc (requires reg edit)

Running on the client pc, allows access to things like printers.

Note:
- You need access to the client.
- Add regedit to run the exe.
- Exe needs to be on the pc.



- Source(s)
  - [From](https://codeburst.io/run-an-external-executable-in-asp-net-core-5c2f8b6cacd9)
  - [2](link2)
{'fraction_non_alphanumeric': 0.12132752992383025, 'fraction_numerical': 0.008705114254624592, 'mean_word_length': 3.001088139281828, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '949769', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1041, 'n_words': 329}