turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Errors running commands on Windows

Open Cyberavater opened this issue 3 years ago • 11 comments

Error:

Exception in thread "main" com.lordcodes.turtle.ShellFailedException: Running shell command failed
	at com.lordcodes.turtle.ShellScript.runCommand(ShellScript.kt:87)
	at com.lordcodes.turtle.ShellScript.command(ShellScript.kt:48)
	at com.lordcodes.turtle.ShellScript.command$default(ShellScript.kt:44)
	at MainKt$main$output$1.invoke(Main.kt:6)
	at MainKt$main$output$1.invoke(Main.kt:5)
	at com.lordcodes.turtle.ShellKt.shellRun(Shell.kt:20)
	at com.lordcodes.turtle.ShellKt.shellRun$default(Shell.kt:19)
	at MainKt.main(Main.kt:5)
	at MainKt.main(Main.kt)
Caused by: java.io.IOException: Cannot run program "echo 'Hello, World!'": CreateProcess error=2, The system cannot find the file specified
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
	at com.lordcodes.turtle.ShellScript.runCommand(ShellScript.kt:82)
	... 8 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
	at java.base/java.lang.ProcessImpl.create(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:494)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:159)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
	... 10 more

I tried running a simple code, is there anything I'm doing wrong here?

import com.lordcodes.turtle.shellRun

fun main() {
    val output = shellRun {
        command("echo 'Hello, World!'")
    }
    println(output)
}

Cyberavater avatar Jul 27 '22 05:07 Cyberavater

Please can you provide more information, such as which version of Turtle you are using, how you are integrating it, which environment you are using it in?

From the error, it is an error from actually trying to create a process, so makes me think it is related to the environment you are running it in, such as where it cannot create a Shell process.

I use the latest version of Turtle a lot via Gradle tasks and it functions correctly, so I think it is related to the environment you are running it in.

lordcodes avatar Jul 27 '22 08:07 lordcodes

It's a simple kotlin project on Windows 11. v0.7.0

On Wed, Jul 27, 2022, 2:48 PM Andrew Lord @.***> wrote:

Please can you provide more information, such as which version of Turtle you are using, how you are integrating it, which environment you are using it in?

From the error, it is an error from actually trying to create a process, so makes me think it is related to the environment you are running it in, such as where it cannot create a Shell process.

I use the latest version of Turtle a lot via Gradle tasks and it functions correctly, so I think it is related to the environment you are running it in.

— Reply to this email directly, view it on GitHub https://github.com/lordcodes/turtle/issues/110#issuecomment-1196440533, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHVSMF2ABDBTRM227ZRG6ODVWDZWFANCNFSM54YI66RA . You are receiving this because you authored the thread.Message ID: @.***>

Cyberavater avatar Jul 27 '22 12:07 Cyberavater

Okay I see. I've not tried using it on Windows if I'm honest. It may depend which shell environment it runs in and which commands you have access to.

lordcodes avatar Jul 27 '22 23:07 lordcodes

I'm a noob at this field, but isn't the command executed on JVM independent of OS?

Cyberavater avatar Jul 28 '22 05:07 Cyberavater

Turtle is for launching external processes. Shell commands are commands you are running in your shell.

For example if you run "git", it is running the Git program on your system via the shell.

The Turtle code itself runs on the JVM, not the commands you execute, they are system dependent. That is the purpose of using a tool to run shell commands.

I hope that makes things clear, closing the issue.

lordcodes avatar Jul 28 '22 06:07 lordcodes

Thanks for clearing things up, I think I understand now. I appreciate your time. BTW, just to be clear I can use Turtle to only execute bash commands not pwsh commands, right?

Cyberavater avatar Jul 28 '22 06:07 Cyberavater

It launches a process and runs what you provide it. I believe it will run any shell or external command.

I haven't tested it on Windows as I'm not a Windows user, so I just can't say.

lordcodes avatar Jul 28 '22 08:07 lordcodes

I have this same error on Windows 11, too

russellbanks avatar Aug 11 '22 13:08 russellbanks

From the comments above, the error was due to running a non-Windows command on Windows.

lordcodes avatar Aug 11 '22 13:08 lordcodes

Surely something like echo would work though, as I am able to run that in a terminal just fine:

fun main() {
    println(
        shellRun {
            command("echo hello")
        }
    )
}

russellbanks avatar Aug 11 '22 13:08 russellbanks

Okay thanks. Sounds like maybe Windows doesn't work for some reason.

I have reopened and made it clear in the title that there are issues running on Windows.

I don't develop on Windows so I'm unlikely to get to this any time soon. My worry would be it could just break again without CI running on windows. I am inclined to say in the README that only Mac and Linux are officially supported for now. Realistically I only use it on Mac, but I do have CI running on Linux.

lordcodes avatar Aug 11 '22 13:08 lordcodes

Hi @lordcodes, I revisited this after a few months as I need to use the library for a project. I think the issue here is that echo on Windows is actually embedded within cmd.exe. Source: https://stackoverflow.com/questions/2684985/running-echo-from-java

Therefore, turtle is working correctly; commands like echo just need to be ran differently on Windows:

fun main() {
    println(
        shellRun {
            command("cmd.exe", listOf("/C", "echo", "Hello world!"))
        }
    )
}

Lots of the other functions do not work on Windows however (they are oriented towards macOS, etc) like:

shellRun {
    files.openApplication("Spotify")
}

Which results in a ShellCommandNotFoundException: Command open not found because open doesn't exist in Windows. The closest I could find for Windows is start [path to exe].

Therefore, if you ever have the chance, it would be a big help if you could try turtle in a Windows sandbox so that it can become a bit more platform independent.

russellbanks avatar Dec 04 '22 16:12 russellbanks

Thank you for letting me know. I'm unlikely to get time to update it for Windows unfortunately. I don't use Windows at all. I will add a note to the README that makes it clear the library has been developed for MacOS and Linux/Windows are untested so may or may not work, i.e they aren't officially supported.

lordcodes avatar Dec 04 '22 16:12 lordcodes

Turtle isn't unusable on Windows, these are just the cases I've found where it isn't working how you'd intend on Windows. The Git command and other commands run fine. The ones I need for my use case work fine too:

fun main() {
    println(shellRun("gh", listOf("--version")))
    println(shellRun("winget", listOf("--version")))
    println(shellRun { git.status() })
}

Still, a note on the ReadMe that not everything works outside of macOS would be helpful.

Edit: I see #119 to improve platform-independence :)

russellbanks avatar Dec 04 '22 16:12 russellbanks

Thank you for even more information. You've been a great help. I will say specifically that some commands were written with MacOS in mind and so may not work as expected on Windows.

lordcodes avatar Dec 04 '22 17:12 lordcodes