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

stdin input #3

Open
ppacory opened this issue Jan 3, 2023 · 2 comments
Open

stdin input #3

ppacory opened this issue Jan 3, 2023 · 2 comments

Comments

@ppacory
Copy link

ppacory commented Jan 3, 2023

#include <stdio.h>

int main()
{
    char name[200];
    fgets(name, 200, stdin);
    printf("You entered: %s", name);
    return 0;
}
$ emcc test.c -o test.js -s EXPORT_NAME='EmscrJSR_test' -s ENVIRONMENT=web,worker -s FILESYSTEM=1 -s MODULARIZE=1 -s EXPORTED_RUNTIME_METHODS=callMain,FS,TTY -s INVOKE_RUN=0 -s EXIT_RUNTIME=1 -s EXPORT_ES6=0 -s USE_ES6_IMPORT_META=0 -s ALLOW_MEMORY_GROWTH=1

copy the created files test.wasm and test.js into your predelivery folder or drag&drop them into the terminal window. You can now execute the command "test" in the terminal and it should ask you for input.

I've done all, it's working but call a window.prompt in the browser ! is there a way to prompt stdin in xterm terminal ?

@z11labs
Copy link
Member

z11labs commented Jan 3, 2023

Hello and thank you for reaching out :)

If you are being prompted, it means that the default WasmRunner was used. It is being used if there is no support for Atomics or SharedArrayBuffers. The prompt is necessary in that case because it stops further WebAssembly execution until the user enters something.

To read STDIN from the xterm.js Terminal, you have to enable the WasmWorker. It runs on another thread and uses Atomics and SharedArrayBuffers to stop its execution while the user enters something into the terminal.

To enable SharedArrayBuffers it is necessary to configure your server or web bundler to use custom HTTPS headers for cross-origin isolation. This should also enable the WasmWorker. You can see if it worked in the terminal welcome message. It should say:

Backend: WebWorker.

Somehow the live demo currently does not support workers. We'll look into that.
Until then you can try the Webpack example (as it has the headers configured) or drop your binaries into a development version of the OpenSSL app.

Best regards
from the CrypTool team

@z11labs
Copy link
Member

z11labs commented Jan 10, 2023

We enabled WasmWorker again in the live demo.

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