diff --git a/extra_tests/snippets/stdlib_os.py b/extra_tests/snippets/stdlib_os.py index 849fc238a..ab40582fd 100644 --- a/extra_tests/snippets/stdlib_os.py +++ b/extra_tests/snippets/stdlib_os.py @@ -502,9 +502,9 @@ with TestWithTempDir() as tmpdir: assert set(collected_files) == set(expected_files) # system() -if "win" not in sys.platform: - assert os.system('ls') == 0 - assert os.system('{') != 0 +if os.name in ('posix', 'nt'): + assert os.system('echo test') == 0 + assert os.system('&') != 0 for arg in [None, 1, 1.0, TabError]: assert_raises(TypeError, os.system, arg) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 5d70327d3..24637d5a9 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -142,6 +142,7 @@ pub(super) mod _os { protocol::PyIterReturn, recursion::ReprGuard, types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter}, + utils::ToCString, vm::VirtualMachine, AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; @@ -1028,6 +1029,14 @@ pub(super) mod _os { }) } + #[cfg(any(unix, windows))] + #[pyfunction] + fn system(command: PyStrRef, vm: &VirtualMachine) -> PyResult { + let cstr = command.to_cstring(vm)?; + let x = unsafe { libc::system(cstr.as_ptr()) }; + Ok(x) + } + #[derive(FromArgs)] struct UtimeArgs { path: OsPath, diff --git a/vm/src/stdlib/posix.rs b/vm/src/stdlib/posix.rs index ed4754dae..1b843bab6 100644 --- a/vm/src/stdlib/posix.rs +++ b/vm/src/stdlib/posix.rs @@ -901,13 +901,6 @@ pub mod module { nix::unistd::pipe2(oflags).map_err(|err| err.into_pyexception(vm)) } - #[pyfunction] - fn system(command: PyStrRef, vm: &VirtualMachine) -> PyResult { - let cstr = command.to_cstring(vm)?; - let x = unsafe { libc::system(cstr.as_ptr()) }; - Ok(x) - } - fn _chmod( path: OsPath, dir_fd: DirFd<0>,