Web Assembly emrun:从批处理脚本 运行 时找不到命令,但在命令 window 中运行正常
Web Assembly emrun: command not found when running from batch script, but runs fine in command window
我使用 Linux (Ubuntu) 的 Windows 子系统设法将 运行 一个 hello world 程序 Web Assembly 放在一起。基本上遵循此处找到的入门页面:https://webassembly.org/getting-started/developers-guide/
我成功地 运行 使用此命令的程序:
emrun --browser "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" --verbose --port 8081 hello.html
当我在命令行中 运行 时,一切都很好,但当我制作一个名为 start.sh 的脚本时,它看起来像这样:
#!/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
我得到标题中提到的错误"emrun: commnand not found"。
第一行“#!/usr/bin/env bash”是从Wasm SDK中的一个.sh文件中复制过来的,所以我觉得对吧?
我还尝试使用 10 提供的编辑环境变量管理器 windows 将 Wasm SDK 添加到 $PATH,但没有成功。
我对批处理脚本没有太多经验,我不确定如何从这里开始。我觉得我遗漏了一些明显的东西,但我无法弄清楚控制台和脚本之间的区别文件 ?
感谢您花时间阅读本文。
再砸脑袋自己也找到答案了!感谢我看到的所有模因,我实际上会与您分享答案。
我编辑了脚本,使其看起来像这样:
#!/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
运行 "$ sudo bash start.sh" 现在在控制台中打印出以下消息:
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
当然,要让这对您有用,您必须编辑每个路径,以便
行
source ./emsdk_env.sh --build=Release
在 emsdk 文件夹中运行。
可能有更好的方法来做到这一点,也许是一种涉及永久设置正确的 PATH 变量以具有上述值的方法,但不幸的是我不确定如何去做。
尽管如此,这个解决方案对我有用。
我使用 Linux (Ubuntu) 的 Windows 子系统设法将 运行 一个 hello world 程序 Web Assembly 放在一起。基本上遵循此处找到的入门页面:https://webassembly.org/getting-started/developers-guide/
我成功地 运行 使用此命令的程序:
emrun --browser "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" --verbose --port 8081 hello.html
当我在命令行中 运行 时,一切都很好,但当我制作一个名为 start.sh 的脚本时,它看起来像这样:
#!/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
我得到标题中提到的错误"emrun: commnand not found"。
第一行“#!/usr/bin/env bash”是从Wasm SDK中的一个.sh文件中复制过来的,所以我觉得对吧? 我还尝试使用 10 提供的编辑环境变量管理器 windows 将 Wasm SDK 添加到 $PATH,但没有成功。
我对批处理脚本没有太多经验,我不确定如何从这里开始。我觉得我遗漏了一些明显的东西,但我无法弄清楚控制台和脚本之间的区别文件 ?
感谢您花时间阅读本文。
再砸脑袋自己也找到答案了!感谢我看到的所有模因,我实际上会与您分享答案。
我编辑了脚本,使其看起来像这样:
#!/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
运行 "$ sudo bash start.sh" 现在在控制台中打印出以下消息:
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
当然,要让这对您有用,您必须编辑每个路径,以便
行source ./emsdk_env.sh --build=Release
在 emsdk 文件夹中运行。
可能有更好的方法来做到这一点,也许是一种涉及永久设置正确的 PATH 变量以具有上述值的方法,但不幸的是我不确定如何去做。 尽管如此,这个解决方案对我有用。