emscripten-core / emscripten-core/emscripten
Standard input and output
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I am trying to port existing C-language program to Webassembly. This program reseives data and user commands from standard input and generates the messages and test to standard output, nothing else. Such program is the https://invisible-island.net/vttest/ , which demonstrates the abilities of VT100-compatible terminal.
I succesfully run some WASM program in worker as in the example: https://stackoverflow.com/questions/32291084/minimal-working-example-for-emscripten-webworker
How to do the following scenario: I have the C or C++ source of application originally designed for PC and compiles by GCC or Clang. The application runs in text console and uses only standard input and standard output for interaction, eventually standard error, nothing else. The mentioned VTTEST seems be such application.
I expect running this application in JavaScript Worker in web browser by doing as minimum source code modifications as possible. When the application prints something, the worker sends message containing the printed contents. When the main thread sends message to the worker, the message contents should be appended into the application input stream. I suppose, that in this case, the application will work exactly the same way, as originally compiled and run in console. The output display will be implemented in main thread and in main threads there all be implementing the input messages.
For example, when the application waits for user data on `scanf`, the application will be hanged in unfinished loop until I send to the worker message containing some strong followed by CR and LF characters.
It is possible to do this? How to compile such application?
The simplest C++ application can be as following:
```
#include
#include
int main()
{
std::string UserData;
std::cout << "Standard test" << std::endl;
bool Work = true;
while (Work)
{
std::cout << "Input some data, write \"exit\" for finish" << std::endl;
std::cin >> UserData;
std::cout << "You input: " << UserData << std::endl;
if (UserData == "exit")
{
Work = false;
}
}
std::cout << "Working finished" << std::endl;
return 0;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.