0
votes

My task is to run a CLI command (in the client's system) and to show the output to the user on the Web app. [assume, a web-based cmd.exe]

Based on reading about WebAssembly's capabilities, I used the .NET CORE Blazor WebAssembly to do the task. But using the System.Diagnostics.ProcessStartInfo in Client throws runtime error Native error= Cannot find the specified file.

Please let me know if my understanding of WebAssembly is wrong. Also, suggest how I could accomplish the task?

Code used in Razor page:

protected override async Task OnInitializedAsync()
{
    quiz = await Http.GetJsonAsync<List<QuizItem>>("Quiz");

    // My actual code...
    string process = @"C:\Windows\System32\cmd.exe", arguments = "start", workingFolder = ".";
    System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo {
        FileName = process, Arguments = arguments, WorkingDirectory = workingFolder,
        CreateNoWindow = false, UseShellExecute = false,
        RedirectStandardError = true, RedirectStandardOutput = true,
    };
    System.Diagnostics.Process proc = System.Diagnostics.Process.Start (startinfo);
    if (proc == null) throw new Exception ($"Unable to execute '{process}'");
}

Console log for reference:

enter image description here

2
Imagine what a security threat this would be. Open a website and suddenly someone accesses your filesystem without any interaction of you.Joelius
So, Can I take it as the task is impossible?Naveen Kumar V

2 Answers

2
votes

The permissions of blazor are limited by the browser javascript sandbox, so you cannot do anything you also cannot do in javascript. Starting processes is one of them.

1
votes

First off, A Blazor WebAssembly App is not a .NET CORE app.

You can't execute CLI commands in a Blazor WebAssembly App which is more or less identical to JavaScript in scope and limitations. A Blazor WebAssembly App is single-threaded and runs in the same sandbox of JavaScript. In JavaScript you can't access the user's file system, which implies that you won't be able to do it using a WebAssembly App.

I'm not sure I get you. If you want to display data retrieved from the server, why can't you display it in Html elements such as input box list box, etc. ?