是否有任何非 Windows 方法可以从本地 .html 文件运行 shell 命令?
- 我有一台Mac。
- 我有一个 html 文件。
- 我有一个配备 javascript 的浏览器。
- 以及我可能需要的其他任何东西。
如何从 html 文件运行 bash 命令?
“我可能还需要什么”可以包括 Java。 TiddlyWiki 使用 Java 小程序将文件保存到我的硬盘上。这很接近我想要的,我只是不知道如何设置。
请忽略目前是否建议这样做。
- I have a Mac.
- I have an html file.
- I have a javascript equipped browser.
- And whatever else I might need.
How do I run a bash command from the html file?
"Whatever else I might need" can include Java. TiddlyWiki uses a Java applet to save a file to my harddrive. This is close to what I want, I just don't know how to set that up.
Please ignore whether or not this is advisable for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
仅使用 Mac、html 文件和支持 Javascript 的浏览器根本不可能做到这一点。
本质上,如果您希望这成为可能,您需要开发自己的浏览器插件;或者也许有人已经创建了这样一个插件来严重违反标准安全边界。
您是否考虑过替代解决方案?为什么要绑定浏览器?
This is simply not possible to do using only your Mac, an html file, and a Javascript-capable browser.
Essentially, you would need to develop your own browser plugin if you ever want this to be possible; alternatively maybe someone has already created such a plugin to grossly violate standard security boundaries.
Have you considered an alternative solution? Why are you bound to a browser?
没有办法做到这一点——这是一个安全问题。浏览器永远不会在 shell 级别上运行网站上的任何内容。
There's no way to do this - it's a security thing. The browser will never run anything from a website on a shell level.
Windows 曾经有 Jscript 和 Wscript,尽管它们实际上并未在浏览器中运行,但它们可以更新 html 视图并作为正确的应用程序运行。
你在这里的目标是什么?如果您的目标是将本地应用程序的 UI 编程为网站,那么肯定有方法可以做到这一点。如果您的目标是将本地应用程序的功能引入 Web 应用程序,也有一些方法可以实现这一点。然而,如果是后者,那么你很可能应该重新考虑你的目标。
Windows used to have Jscript and Wscript, which, although they were not actually run in the browser, they could update html views and run as proper applications.
What is your goal here? If your goal is to program a UI for a local application as a website, there are certainly ways to do that. If your goal is to bring abilities of local applications to a web applications, there are ways to do that as well. However, if it is the latter, then it is most likely that you should rethink your goals.
我知道这样做的唯一方法是使用 WScript.Shell 对象(仅在 Windows 上可用,即使如此,如果客户端 PC 上没有一些非常不寻常的安全设置,它也可能无法使用),或使用 ActiveX 控件。
我不知道 ActiveX 控件是否可以在 Mac 上运行,或者您是否可以使用 ActiveX 控件执行与 Windows PC 上相同的操作,但这可能值得研究。
The only way I know of doing this is to use the WScript.Shell object (only available on Windows and even then it probably won't without some pretty unusual security settings on the client PC), or using an ActiveX control.
I don't know if an ActiveX control will even work on a Mac, or if you can do the same things with an ActiveX control as you can on a Windows PC, but it might be worth looking into.
我不确定这是如何在 Mac 上完成的,但这是我的 Windows 解决方案。您需要创建自己的协议(又名 myproto:// 而不是 http://),然后在监听端的注册表中您有一个程序 - 使用像 AutoIt 这样的脚本语言在这里很好。您将收到一个 URL,该 URL 必须进行转义才能显示您发送到临时程序的任何消息,然后让您的程序执行任何适合的操作。该消息可以是直接命令行字符串(不推荐:P)或您拥有的其他内容。在浏览器端,您只需创建像 myproto://这样的 url所以用手写起来一点乐趣都没有,哈哈。
I am not sure how this is done on a mac, but here is my windows solution. You need to create your own protocol (aka myproto:// instead of http://) then in the registry at the listening end you have a program -- using a scripting language like AutoIt is good here. You will recieve a URL, that url has to be UNescaped to reveal whatever message you are sending to your ad-hoc program, then let your program do whatever suits. The message could be a direct command line string (not recommended :P) or what have you. On the browserside you just make urls like myproto://<escaped command> so they are no fun to write by hand haha.