Fix for Windows drive changes

This adds a drive change command to every Windows `execAction` call that starts with the `cd` command.
Tested with the `libmodbus` C library (https://github.com/stephane/libmodbus).
This commit is contained in:
matkuki 2019-10-21 21:18:01 +02:00 committed by GitHub
commit 35cd391ecd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,7 +29,14 @@ proc execAction*(cmd: string, retry = 0, nostderr = false): string =
ccmd = ""
ret = 0
when defined(Windows):
ccmd = "cmd /c " & cmd
var filteredCmd = cmd
if cmd.startsWith("cd"):
var
colonIndex = cmd.find(":")
driveLetter = cmd.substr(colonIndex-1, colonIndex)
if driveLetter[0].isAlphaAscii() and driveLetter[1] == ':':
filteredCmd = &"{driveLetter} && {cmd}"
ccmd = "cmd /c " & filteredCmd
elif defined(posix):
ccmd = cmd
else: