An elegent way to handle OS specific slashes?

I’m using the ‘Exec’ build-in tasks, and I’m wondering if there is a cleaner way to handle OS specific slashes/backslashes. This task need to be able to run on both Windows and Linux:

task myTask(type: Exec) {

    String command = "command ${projectDir}/${solution}/*.exe"

    if  (operationSystem == 'windows' {
        command = command.replace("/", "\\")
        commandLine('cmd /c ' + command)
    } else {

I’m already not too happy about the if/else for the ‘cmd /c’ (it’s a shell command), is there any way to avoid the slash replacement?

You could use File.separator instead of /.