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

fix: Command cannot be executed on Windows #458

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/jennifer/adapter/command_shell/i_command_shell.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ require "./command"
module Jennifer
module Adapter
abstract class ICommandShell
OPTIONS_PLACEHOLDER = %("${@}")
SUDO = "sudo"

OPTIONS_PLACEHOLDER = {% if flag?(:win32) %} "" {% else %} %("${@}") {% end %}
SUDO = {% if flag?(:win32) %} "" {% else %} "sudo" {% end %}
abstract def execute(command) : NamedTuple

getter config : Config
Expand All @@ -15,7 +14,13 @@ module Jennifer

private def invoke(command_string, options) : NamedTuple
io = IO::Memory.new
result = Process.run(command_string, options, shell: true, output: io, error: io)

result = {% if flag?(:win32) %}
Process.run("cmd", ["/c", command_string] + options, output: io, error: io)
{% else %}
Process.run(command_string, options, shell: true, output: io, error: io)
{% end %}

raise Command::Failed.new(result.exit_code, io) if result.exit_code != 0
{status: result, output: io}
end
Expand Down