Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should the hello_embed.rs example print something? #3546

Open
RudolfVonKrugstein opened this issue Feb 10, 2022 · 1 comment
Open

Should the hello_embed.rs example print something? #3546

RudolfVonKrugstein opened this issue Feb 10, 2022 · 1 comment

Comments

@RudolfVonKrugstein
Copy link

@RudolfVonKrugstein RudolfVonKrugstein commented Feb 10, 2022

Hi,

when running the hello_embed.rs example on windows, it works fine but I don't see the output Hello World! (which I would expect from the python statement print("Hello World!")). Should rustpython print to stdout when python calls print? Or do I have to redirect that somehow?

Thanks!

@bit-garden
Copy link

@bit-garden bit-garden commented Mar 17, 2022

I'm getting the same behavior.

use rustpython::rustpython_vm as vm;

fn main() -> vm::PyResult<()> {
  vm::Interpreter::default().enter(|vm| {
    let scope = vm.new_scope_with_builtins();

    let code_obj = vm
      .compile(
        r#"print("Hello World!")"#,
        vm::compile::Mode::Exec,
        "<embedded>".to_owned(),
      )
      .map_err(|err| vm.new_syntax_error(&err))?;

    println!("start");
    vm.run_code_obj(code_obj, scope)?;
    println!("end");

    Ok(())
  })
}

results in

cargo run
   Compiling pytest v0.1.0 (C:\Users\Dakun\Downloads\_stuff\code\rust\pytest)
    Finished dev [unoptimized + debuginfo] target(s) in 2.56s
     Running `target\debug\pytest.exe`
start
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants