added os.findExe
This commit is contained in:
parent
ec67d98286
commit
5055d30753
3 changed files with 14 additions and 12 deletions
|
|
@ -1231,4 +1231,17 @@ proc getFileSize*(file: string): biggestInt {.rtl, extern: "nos$1".} =
|
||||||
close(f)
|
close(f)
|
||||||
else: OSError()
|
else: OSError()
|
||||||
|
|
||||||
|
proc findExe*(exe: string): string =
|
||||||
|
## Searches for `exe` in the current working directory and then
|
||||||
|
## in directories listed in the ``PATH`` environment variable.
|
||||||
|
## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
|
||||||
|
## is added an ``.exe`` file extension if it has no extension.
|
||||||
|
result = addFileExt(exe, os.exeExt)
|
||||||
|
if ExistsFile(result): return
|
||||||
|
var path = os.getEnv("PATH")
|
||||||
|
for candidate in split(path, pathSep):
|
||||||
|
var x = candidate / result
|
||||||
|
if ExistsFile(x): return x
|
||||||
|
result = ""
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,6 @@ when defined(tinyc):
|
||||||
else:
|
else:
|
||||||
const runCmd = "c -r"
|
const runCmd = "c -r"
|
||||||
|
|
||||||
when not defined(findExe):
|
|
||||||
# candidate for the stdlib:
|
|
||||||
proc findExe(exe: string): string =
|
|
||||||
## returns exe if the exe cannot be found
|
|
||||||
result = addFileExt(exe, os.exeExt)
|
|
||||||
if ExistsFile(result): return
|
|
||||||
var path = os.getEnv("PATH")
|
|
||||||
for candidate in split(path, pathSep):
|
|
||||||
var x = candidate / result
|
|
||||||
if ExistsFile(x): return x
|
|
||||||
result = ""
|
|
||||||
|
|
||||||
var nimExe = findExe("nimrod")
|
var nimExe = findExe("nimrod")
|
||||||
if nimExe.len == 0: nimExe = "../bin" / addFileExt("nimrod", os.exeExt)
|
if nimExe.len == 0: nimExe = "../bin" / addFileExt("nimrod", os.exeExt)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ Additions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
- Added ``re.findAll``, ``pegs.findAll``.
|
- Added ``re.findAll``, ``pegs.findAll``.
|
||||||
|
- Added ``os.findExe``.
|
||||||
|
|
||||||
|
|
||||||
2010-10-20 Version 0.8.10 released
|
2010-10-20 Version 0.8.10 released
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue