Merge pull request #145 from matkuki/patch-1

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:
genotrance 2019-10-23 10:52:59 -05:00 committed by GitHub
commit 3c960c140c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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