Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to run a command prompt command if on windows and process fails to start #99

Closed
damianh opened this issue Jan 1, 2019 · 5 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@damianh
Copy link
Contributor

damianh commented Jan 1, 2019

We have this code in our build at https://github.com/SQLStreamStore/SQLStreamStore.HAL/blob/f3bfa641154b7c0a82c0d94e1ddec9ffd6c8c774/build/Program.cs#L131-L134

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
    Run("cmd", "/c yarn", workingDirectory);
else
    Run("yarn", args, workingDirectory);

I'd rather just write

Run("yarn", args, workingDirectory);

But running that results in an exception on windows:

Bullseye/build-hal-docs: System.ComponentModel.Win32Exception (2): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at SimpleExec.ProcessExtensions.EchoAndStart(Process process, Boolean noEcho) in C:\projects\simple-exec\SimpleExec\ProcessExtensions.cs:line 33
   at SimpleExec.Command.Run(String name, String args, String workingDirectory, Boolean noEcho) in C:\projects\simple-exec\SimpleExec\Command.cs:line 29
   at build.Program.<>c.<Main>b__6_0() in E:\dev\damianh\SQLStreamStore\build\Program.cs:line 22
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at Bullseye.Internal.ActionTarget.RunAsync(Boolean dryRun, Boolean parallel, Logger log, Func`2 messageOnly) in C:\projects\bullseye\Bullseye\Internal\ActionTarget.cs:line 25

Suggestion: on windows, catch this and then attempt Run("cmd", $"/c {name} {arg}", workingDirectory); ?

@damianh
Copy link
Contributor Author

damianh commented Jan 1, 2019

Added this to my code and it seems to work (not sure about the method name, but what-evs):

        static void RunCmd(string name, string args = null, string workingDirectory = null, bool noEcho = false)
        {
            try
            {
                Run(name, args, workingDirectory, noEcho);
            }
            catch (Win32Exception ex) when (ex.NativeErrorCode == 2) // The system cannot find the file specified.
            {
                var cmdArgs = $"/C {name}";
                if (args != null)
                {
                    cmdArgs += " " + args;
                }
                Run("cmd", cmdArgs, workingDirectory, noEcho);
            }
        }

@adamralph
Copy link
Owner

@damianh what is the root cause of not being able to run yarn on Windows without cmd?

@adamralph
Copy link
Owner

adamralph commented Jan 1, 2019

FTR this was discussed at great length in Slack.

@adamralph adamralph self-assigned this Jan 1, 2019
@damianh
Copy link
Contributor Author

damianh commented Jan 3, 2019

Yeah we figured some stuff out :)

The slack discussion will eventually be purged but the gist of it is that on windows we launch processes via cmd.exe /C so cmd and bat files (yarn.cmd, npm.cmd) on path can also be launched.

@adamralph
Copy link
Owner

Closing in favour of #100

@adamralph adamralph added the wontfix This will not be worked on label Jan 3, 2019
@adamralph adamralph closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants