-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09a4386
commit 60648a2
Showing
2 changed files
with
48 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
|
||
## see docs.python.org/3/library/os.html | ||
## | ||
## Also export everything of std/os | ||
## | ||
## as the following will fail to compile: | ||
## | ||
## ```Nim | ||
## import std/os | ||
## import pylib/Lib/os | ||
## os.path.join ... | ||
## ``` | ||
## | ||
## not completed yet | ||
|
||
import std/os | ||
export os | ||
|
||
import ./os_impl/[consts, posix_like, utils, path] | ||
export consts, posix_like, utils, path | ||
|
||
|
||
|
||
## see docs.python.org/3/library/os.html | ||
## | ||
## Also export everything of std/os | ||
## | ||
## as the following will fail to compile: | ||
## | ||
## ```Nim | ||
## import std/os | ||
## import pylib/Lib/os | ||
## os.path.join ... | ||
## ``` | ||
## | ||
## not completed yet | ||
|
||
import std/os | ||
export os | ||
|
||
import ./os_impl/[consts, posix_like, subp, utils, path] | ||
export consts, posix_like, subp, utils, path | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
when not defined(js): | ||
proc c_system(cmd: cstring): cint{.importc: "system", header: "<stdlib.h>".} | ||
|
||
func system*(cmd: string): int{.discardable.} = | ||
## os.system | ||
runnableExamples: | ||
const | ||
# can use `os.devnull` | ||
mydevnull = when defined(windows): "nul" else: "/dev/null" | ||
e2null = "echo 1 >" & mydevnull | ||
assert system(e2null) == 0 | ||
|
||
when defined(js): | ||
let jsStr = cmd.cstring | ||
var res: c_int | ||
asm """ | ||
const {exec} = require('node:child_process'); | ||
let childProcess = exec(`jsStr`); | ||
`res` = childProcess.exitCode; | ||
""" | ||
result = res.int | ||
else: | ||
c_system cmd.cstring | ||
|