From 35cd391ecd62b6c0c4e9d28ebde0af0d9f68e5e0 Mon Sep 17 00:00:00 2001 From: matkuki Date: Mon, 21 Oct 2019 21:18:01 +0200 Subject: 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). --- nimterop/build.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nimterop/build.nim b/nimterop/build.nim index f96593e..c1eb7ee 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -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: -- cgit v1.2.3 From 36ef771ea82fe5c775100195d55e18e960fd5cc7 Mon Sep 17 00:00:00 2001 From: matkuki Date: Tue, 22 Oct 2019 23:36:49 +0200 Subject: Updated to search for "cd x:" Tested again with `libmodbus` and it works. --- nimterop/build.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nimterop/build.nim b/nimterop/build.nim index c1eb7ee..b2fbc48 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -1,4 +1,4 @@ -import macros, osproc, sets, strformat, strutils, tables +import macros, osproc, sets, strformat, strutils, regex, tables import os except findExe, sleep @@ -29,13 +29,13 @@ proc execAction*(cmd: string, retry = 0, nostderr = false): string = ccmd = "" ret = 0 when defined(Windows): - 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}" + var + filteredCmd = cmd + matches: RegexMatch + if cmd.find(re"cd\s+(\D)\:", matches): + var driveLetter = cmd[matches.group(0)[0]] + filteredCmd = &"{driveLetter}: && {cmd}" + echo filteredCmd ccmd = "cmd /c " & filteredCmd elif defined(posix): ccmd = cmd -- cgit v1.2.3 From 3765862b6ee94ca661ca24a636af950bfc37d9c4 Mon Sep 17 00:00:00 2001 From: matkuki Date: Wed, 23 Oct 2019 16:53:43 +0200 Subject: Removed the regex stuff --- nimterop/build.nim | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nimterop/build.nim b/nimterop/build.nim index b2fbc48..cbf9b25 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -1,4 +1,4 @@ -import macros, osproc, sets, strformat, strutils, regex, tables +import macros, osproc, sets, strformat, strutils, tables import os except findExe, sleep @@ -29,13 +29,15 @@ proc execAction*(cmd: string, retry = 0, nostderr = false): string = ccmd = "" ret = 0 when defined(Windows): - var - filteredCmd = cmd - matches: RegexMatch - if cmd.find(re"cd\s+(\D)\:", matches): - var driveLetter = cmd[matches.group(0)[0]] - filteredCmd = &"{driveLetter}: && {cmd}" - echo filteredCmd + 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 -- cgit v1.2.3