You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
1.2 KiB

use deno_core::CoreIsolate;
use deno_core::Op;
use deno_core::Script;
use deno_core::StartupData;
use deno_core::ZeroCopyBuf;
use std::process::Command;
#[derive(Clone, Debug, PartialEq)]
struct CmdArgs {
cmdline: String,
}
impl From<&[u8]> for CmdArgs {
fn from(buf: &[u8]) -> Self {
let str = String::from_utf8_lossy(buf)
.trim_end_matches(char::from(0))
.to_string();
println!("{:?}", str);
return CmdArgs { cmdline: str };
}
}
fn op_run_shell(_isolate: &mut CoreIsolate, control_buf: &[u8], _zcb: Option<ZeroCopyBuf>) -> Op {
let args = CmdArgs::from(control_buf);
let out = Command::new("/bin/sh")
.args(&["-c", &args.cmdline])
.output()
.unwrap();
return Op::Sync(out.stdout.into_boxed_slice());
}
fn main() {
let mut isolate = CoreIsolate::new(
StartupData::Script(Script {
filename: "bundle.js",
source: include_str!("bundle.js"),
}),
false,
);
isolate.register_op("runShell", op_run_shell);
let mut runtime = tokio::runtime::Builder::new().enable_all().build().unwrap();
runtime.block_on(isolate).unwrap()
}