There was an error while loading. Please reload this page.
1 parent 1fd8787 commit 5b26281Copy full SHA for 5b26281
1 file changed
vm/src/sysmodule.rs
@@ -1,4 +1,4 @@
1
-use std::{env, mem};
+use std::{env, mem, path};
2
3
use crate::builtins;
4
use crate::frame::FrameRef;
@@ -28,9 +28,18 @@ fn argv(vm: &VirtualMachine) -> PyObjectRef {
28
}
29
30
fn executable(ctx: &PyContext) -> PyObjectRef {
31
- if let Ok(path) = env::current_exe() {
32
- if let Ok(path) = path.into_os_string().into_string() {
33
- return ctx.new_str(path);
+ if let Some(exec_path) = env::args().next() {
+ if path::Path::new(&exec_path).is_absolute() {
+ return ctx.new_str(exec_path);
34
+ }
35
+ if let Ok(dir) = env::current_dir() {
36
+ if let Ok(dir) = dir.into_os_string().into_string() {
37
+ return ctx.new_str(format!(
38
+ "{}/{}",
39
+ dir,
40
+ exec_path.strip_prefix("./").unwrap_or(&exec_path)
41
+ ));
42
43
44
45
ctx.none()
0 commit comments