mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
fix: runtime args bug
This commit is contained in:
parent
6a925f38bd
commit
bb613c20d6
3 changed files with 12 additions and 9 deletions
|
@ -853,7 +853,7 @@ pub fn spawn_py(py_command: Option<&str>, code: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec_py_code(code: &str, output: Output) -> std::io::Result<ExitStatus> {
|
pub fn exec_py_code(code: &str, args: &[&str], output: Output) -> std::io::Result<ExitStatus> {
|
||||||
let mut out = if cfg!(windows) {
|
let mut out = if cfg!(windows) {
|
||||||
let fallback = |err: std::io::Error| {
|
let fallback = |err: std::io::Error| {
|
||||||
// if the filename or extension is too long
|
// if the filename or extension is too long
|
||||||
|
@ -867,6 +867,7 @@ pub fn exec_py_code(code: &str, output: Output) -> std::io::Result<ExitStatus> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Command::new(which_python())
|
Command::new(which_python())
|
||||||
.arg(tmp_file)
|
.arg(tmp_file)
|
||||||
|
.args(args)
|
||||||
.stdout(output.clone())
|
.stdout(output.clone())
|
||||||
.spawn()
|
.spawn()
|
||||||
} else {
|
} else {
|
||||||
|
@ -876,12 +877,13 @@ pub fn exec_py_code(code: &str, output: Output) -> std::io::Result<ExitStatus> {
|
||||||
Command::new(which_python())
|
Command::new(which_python())
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(code)
|
.arg(code)
|
||||||
|
.args(args)
|
||||||
.stdout(output.clone())
|
.stdout(output.clone())
|
||||||
.spawn()
|
.spawn()
|
||||||
.or_else(fallback)
|
.or_else(fallback)
|
||||||
.expect("cannot execute python")
|
.expect("cannot execute python")
|
||||||
} else {
|
} else {
|
||||||
let exec_command = format!("{} -c \"{code}\"", which_python());
|
let exec_command = format!("{} -c \"{code}\" {}", which_python(), args.join(" "));
|
||||||
Command::new("sh")
|
Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(exec_command)
|
.arg(exec_command)
|
||||||
|
|
|
@ -5,8 +5,8 @@ use std::io::{BufReader, Read, Write as _};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::ExitStatus;
|
use std::process::ExitStatus;
|
||||||
|
|
||||||
|
use erg_common::config::ErgConfig;
|
||||||
use erg_common::impl_display_from_debug;
|
use erg_common::impl_display_from_debug;
|
||||||
use erg_common::io::Output;
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use erg_common::log;
|
use erg_common::log;
|
||||||
use erg_common::opcode::CommonOpcode;
|
use erg_common::opcode::CommonOpcode;
|
||||||
|
@ -453,8 +453,12 @@ impl CodeObj {
|
||||||
format!("import marshal; exec(marshal.loads(b'{bytecode}'))")
|
format!("import marshal; exec(marshal.loads(b'{bytecode}'))")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(self, py_magic_num: Option<u32>, output: Output) -> std::io::Result<ExitStatus> {
|
pub fn exec(self, cfg: &ErgConfig) -> std::io::Result<ExitStatus> {
|
||||||
exec_py_code(&self.executable_code(py_magic_num), output)
|
exec_py_code(
|
||||||
|
&self.executable_code(cfg.py_magic_num),
|
||||||
|
&cfg.runtime_args,
|
||||||
|
cfg.output.clone(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tables_info(&self) -> String {
|
fn tables_info(&self) -> String {
|
||||||
|
|
|
@ -289,10 +289,7 @@ impl Runnable for DummyVM {
|
||||||
eart.errors
|
eart.errors
|
||||||
})?;
|
})?;
|
||||||
art.warns.write_all_to(&mut self.cfg_mut().output);
|
art.warns.write_all_to(&mut self.cfg_mut().output);
|
||||||
let stat = art
|
let stat = art.object.exec(self.cfg()).expect("failed to execute");
|
||||||
.object
|
|
||||||
.exec(self.cfg().py_magic_num, self.cfg().output.clone())
|
|
||||||
.expect("failed to execute");
|
|
||||||
let stat = ExitStatus::new(stat.code().unwrap_or(0), art.warns.len(), 0);
|
let stat = ExitStatus::new(stat.code().unwrap_or(0), art.warns.len(), 0);
|
||||||
Ok(stat)
|
Ok(stat)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue