2

I am running a .NET application on wine in linux. I am trying to run a command that runs a shell script present in the linux. This is my code inside the .NET application, calling the command:

           System.Diagnostics.Process process = new System.Diagnostics.Process();
           System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
           startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
           startInfo.FileName = "cmd";
           startInfo.Arguments = "/C /bin/gnome-terminal -- sh -e /bin/MyScripts/script.sh";
           process.StartInfo = startInfo;
           process.Start();

The gives me error saying that

Can't recognize /bin/gnome-terminal -- sh -e /bin/MyScripts/script.sh as as an internal or external command, operable program or batch file.

However, if I try to run that command directly on wine, that command works fine and executes the script. I have tried running it directly like this:

wine cmd /c /bin/gnome-terminal -- sh -e /bin/MyScripts/script.sh

The application is run on wine using the following command:

wine Application.exe

So I assume if that application runs the command, it will be called the same way it is called directly, so why I am seeing such inconsistent behaviour? What am I doing wrong and what change should I make for the command to work through the application?

Shantanu Shinde
  • 932
  • 3
  • 23
  • 48
  • If I understand you correctly, your C# application is already running inside Linux (i.e. WSL). Why then can't you set the startInfo.FileName to `sh` and the arguments to `-e /bin/MyScripts/script.sh`? – user1934428 Sep 17 '21 at 11:18
  • Have you tried `cmd /c start /unix /bin/gnome-terminal ....`? See [Execute Shell Commands from Program running in WINE](https://stackoverflow.com/a/29632463/10318835) – Steeeve Sep 17 '21 at 15:35
  • I don't think you'll need to set `UseShellExecute = true` but that is sometimes the magic wand that you need to make `Process.Start()` work. – nateirvin Sep 21 '21 at 17:51

1 Answers1

-3

Try

startInfo.FileName = "cmd.exe";
UHM
  • 303
  • 1
  • 7
  • I have tried that but it gives the same result. from my knowledge using `cmd.exe` and `cmd` are the same – Shantanu Shinde Sep 17 '21 at 10:59
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/29850984) – Noam Yizraeli Sep 17 '21 at 16:59
  • 1
    @NoamYizraeli: It very much provides an answer. It may be a wrong answer—and based on the OP's comments, it sounds like that might be the case. But, if so, the correct recourse is to downvote it, as other members of the community have already done. It doesn't need to be deleted ([source](https://meta.stackoverflow.com/questions/287563/youre-doing-it-wrong-a-plea-for-sanity-in-the-low-quality-posts-queue)). – Jeremy Caney Sep 18 '21 at 00:18
  • @JeremyCaney I see but because it doesn't help and it initially suppose to be served as a comment I still stand that's it should be deleted – Noam Yizraeli Sep 18 '21 at 07:57
  • 1
    @NoamYizraeli: It’s not a comment; it’s offering a solution. It’s certainly not up to my own standards of what I’d feel comfortable leaving as an answer. But our role as reviewers is to enforce the community’s established standards, not our own. If you disagree with those standards, it’s worth taking the issue up on meta. There’s definitely a faction of contributors that agree we should delete, and not simply downvote, low quality, incorrect, and/or code-only answers. – Jeremy Caney Sep 18 '21 at 17:14
  • ok, I understand – Noam Yizraeli Sep 18 '21 at 17:18
  • UHM: To avoid the risk of having your answers either deleted or downvoted in the future, I recommend adding more explanation as to why something works, verifying your answer if you’re able to, and finally, if you don’t have time for either, leaving it as a comment. (If you delete this comment, you should have enough reputation to leave comments again.) – Jeremy Caney Sep 18 '21 at 17:19