Web Assembly emrun: command not found when running from batch script, but runs fine in command window

Viewed 392

I managed to put together and run a hello world program Web Assembly, using Windows Subsystem for Linux (Ubuntu). Essentially following the getting started page found here: https://webassembly.org/getting-started/developers-guide/

I successfully ran the program with this command:

emrun --browser "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" --verbose --port 8081 hello.html

All is well and dandy when I run this in the command line, but when i made a script called start.sh that looks like this:

#!/usr/bin/env bash
echo "Starting hello world in chrome."
emrun --browser "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" --verbose --port 8081 hello.html

I get the error mentioned in the title "emrun: commnand not found".

The first line "#!/usr/bin/env bash" was copied from one of the .sh files in the Wasm SDK, so I think its right? Ive also tried adding the Wasm SDK to the $PATH using the edit enviromnent variables manager windows 10 provides, but with no luck.

I dont have a lot of experience with batch scripts, and im not sure how to proceed from here.. I feel like im missing something obvious but I just cant figure out what the difference is between the console and the script file ?

Thanks for taking the time to read this.

1 Answers

Found an answer myself after some more head smashing! Thanks to all the memes I've seen i'll actually share the answer with you.

I edited the script so it looks like this:

#!/usr/bin/env bash
cd ..
cd Wasm/emsdk
source ./emsdk_env.sh --build=Release
cd ..
cd ..
cd hello
emcc hello.c -o hello.html
echo "Starting hello world in chrome."
emrun --browser "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" --verbose --port 8081 hello.html

Running "$ sudo bash start.sh" now prints out the following message in the console:

Adding directories to PATH:
PATH += /home/elaurora/Wasm/emsdk
PATH += /home/elaurora/Wasm/emsdk/fastcomp/emscripten
PATH += /home/elaurora/Wasm/emsdk/node/12.9.1_64bit/bin

Setting environment variables:
EMSDK = /home/elaurora/Wasm/emsdk
EM_CONFIG = /home/elaurora/.emscripten
EMSDK_NODE = /home/elaurora/Wasm/emsdk/node/12.9.1_64bit/bin/node

Starting hello world in chrome.
... then a bunch of unrelated stuff regarding the server that was just started

Of course for this to work for you, you'll have to edit each of the paths so that the line

source ./emsdk_env.sh --build=Release

is run within the emsdk folder.

There is probably a better way to do this, perhaps a way involving permanently setting the correct PATH variables to have the above values, but unfortunately I am not sure how to go about this. Nonetheless, this solution is working for me.

Related