Run HTML file via Bash? Possible? - javascript

I have a html file that when run in a browser such as Chrome and that contain javascript instructions, it sends the "emit" message to my websockets server and displays the value on that page.
Is there a way to call this same html file from a bash script as I'm wanting to insert data into a MySQL database which will ultimately call that html file to send an update to the websocket.
Hopefully that makes sense but hopefully there is a way to do it too :)

If you are only focused on rendering the HTML page (and not interacting with it via buttons or something) you may find this link helpful: Running HTML from Command Line

If you try to execute javascript instruction in your server without using a browser, I recommand you to use Node.JS with a real js script without html.
Otherwise you can try to run an html file with js instruction inside using something like phantomjs but I think is less performant than using Node correctly.
EDIT
It is Javascript yes, but I need to "Import" the socket.io.js file into the same script I have created and my browser I'm having to use doesn't support the new Javascript import methods. So I'm writing as HTML which calls the Javascript, otherwise I would use nodejs
I think you can import the socket.io lib in node application using npm.
https://www.npmjs.com/package/socket.io
The documentation says that you can use a client inside a node script too :
Socket.IO enables real-time bidirectional event-based communication. It consists in:
a Node.js server (this repository)
a Javascript client library for the browser (or a Node.js client)

Related

copy file from one folder to another folder using javascript or jquery

I have a file path like this \\ptrisf02\group2\Engine_Follow\V2500-A5\V2500-A5_e-Archive\EV15159-02\Pictures_INC\INCOMING-LX\Oil tank.jpg in my database. I want to copy it another folder like T:\\Temp\\ when the button clicked in my jsp page. Is there any method to do this using javascript or jquery? I tried ActiveXObject but it gives me this error Automation server can't create object in IE.
There are two main issues you are going to run into with trying to use JS in any flavour:
Permissions and security.
JS is sandboxed.
The better way would be to use JS to fire an Ajax call which does the file copy/move for you using whatever server side language the web server is based on. That is provided that the web server actually has the permission to do so.

Using javascript to move a file on a server

So I have this html page. Inside of it is a bit of javascript code that talks to a flash application.
During the flash application's lifecycle, it'll save a file to a place on the server using the javascript on the html page.
How can I use javascript to take the file I just saved and move it to a different location?
You cannot. Javascript works on a client and don't have an access to the server's filesystem.
You can only trigger a script on the server that does that.
As you said you have node js installed and running on the server,it is possible for you to move a file using the nodejs filesystem api: http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback
For this to work you would need to monitor and detect when new files are saved in a certain folder, which should be possible using: http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
Happy coding!

making exe form HTML and Javascript

I was wondering I have PHP based server side stuff that accepts ajax requests and sends back JSON for JS. And I have HTML and JS based "client" now I would like to create exe(windows aplication) that would look the same as the "client" in browser but without browser. Preferably somehow grab that HTML and JS and "compile it" to regural client that would still send out AJAX calls and procesing JSON data.
Edit:
To clarify things:
Server(on webserver) is PHP procesing incoming AJAX calls and diplaing JSON as result.
Client(what I want to convertt to exe) is HTML and JS(Jquery) page(application).
I want for user to have option two to dowload client for windows so he/she dont have to use browser.
With https://electron.atom.io/ from Github you can develop Windows, Mac and Linux applications with Javascript, Html and CSS. You can also build mobile application with your web development skills. https://cordova.apache.org/.
You can use Electron, but if you just want something quick and easy to use, try Scriptonit. It's exactly for this kind of use. (Check out the documentation and the examples to see if this is the one for you.)
It's basically one exe plus a few sidecar files in a folder called app/, then it just works like a local browser without the frames & head. Also, it can access local files and run OS commands, even capture their output.
Side note 1: Yes it's mine, as you can see on the link - but no, that's not why I'm recommending it
Side note 2: It's 0.9 so it's not perfect, let me know if it misbehaves.
I don't think you can make a desktop application with markup languages. but then am also a newbie in this stuff but what I think you need is to develop a GUI in a programming language like java for example Swing docs.oracle.com/javase/tutorial/uiswing/ to mimic the apearance of your webpage. Then connect to your server by socket programming.

Interfacing with Local Perl Script from a Web UI

Given that I have a local Perl script that prints "Hello" in a windows command prompt.
I want to make a Web Interface that when I click a button on an HTML page using Javascript or something, I'd be able to execute this local Perl Script. I have tried hosting the page on Localhost in an Xampp Apache server however this uses the Perl installed on Xampp.
Is there anyway to interact with local Perl from a Web User Interface? i.e. Running a perl script in the local shell from a Web UI.
I usually run a perl script that works as a primitive web server. Upon startup it prints a URL which can be used to access it.
This can be done with the following modules:
use HTTP::Daemon;
use HTTP::Status;
use HTTP::Response;
in about 60 lines of code.
Can't post my code, but here is a more elaborate sample (it uses fork, which is an improvement over what I have): http://www.perlmonks.org/?node_id=415908
Look into Node JS... it can call perl from the webpage, is very very simple to set up and get a localhost site going, and is free.

How to execute shell scripts from a web page via javascript/jquery and get its results in a string?

in a simple html file opened locally via firefox I need some javascript code to execute a command (maybe "ls") and get it's result in a string I can use in js/jquery to alter the page contents.
I already know this is a generally bad idea, but I have to make this little local html file capable of running several scripts without a server and without cgi.
In the past I've used to install a plugin in TiddlyWiki (www.tiddlywiki.com) to execute external commands (firefox requested authorization for every operation), so javascript can do it, but how to get command result in js after execution?
I don't believe there's any way to do this without a cooperating browser plug-in. The browser plug-in would be told what command to execute via javascript, it would go execute that command and then call you back with a callback when the results were available. This could be very dangerous as giving the browser access to your local system in almost anyway opens you up to lots of types of attacks (which is why browsers don't offer this capability).

Categories

Resources