Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6101

Executing WSL Ubuntu Commands from C# - Output Capture Issues

$
0
0

I'm writing a C# code in Visual Studio Code on Windows 11 to run an application from my WSL Ubuntu and saves the output as a string file.

I've already installed WSL and Ubuntu. When I write the following commands directly on my WSL Ubuntu terminal, they produce the expected results.

root@DESKTOP-JCGMG2B:~# cd ENHSP-Public/root@DESKTOP-JCGMG2B:~/ENHSP-Public# java -jar enhsp-dist/enhsp.jar -o Domain-numerical.pddl -f Problem-numerical.pddl -ha true -s wastar -h hmrp -wh 4

To run these two commands from my VSCode, I wrote the following function:

   public static string RunWSLCommand(string command){    var startInfo = new ProcessStartInfo    {        FileName = "wsl",        Arguments = $"-d Ubuntu -e \"{command}\"",        RedirectStandardOutput = true,        UseShellExecute = false,        CreateNoWindow = true    };    var process = new Process    {        StartInfo = startInfo    };    process.Start();      string output = process.StandardOutput.ReadToEnd();    process.WaitForExit();    return output;  }

Unfortunately, I'm only getting output when I use the "ls" command. For example, the command"cd ~; ls" doesn't produce any output.

Can anyone help me with this? How can I correctly execute my application from Ubuntu using this C# function?

Thank you.

I have also tried to give a bash file as input. But it doesn't work and I don't understand why.


Viewing all articles
Browse latest Browse all 6101

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>