开发者

Is there any non-Windows way to run a shell command from a local .html file?

开发者 https://www.devze.com 2023-02-23 15:16 出处:网络
I have a Mac. I have an html file. I have a javascript equipped browser. And whatever else I might need.
  • 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?

"Whate开发者_如何学Cver 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.


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?


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 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号