I'm trying to run PhantomJS from a Grails application running on a Tomcat 7 instance on Linux (Ubuntu 13.04).
I'm sure PhantomJS is installed correctly because I can execute it from the command line. I'm using it to make a screen capture of a web page (http://phantomjs.org/screen-capture.html).
When I run the command from the command line, it works great, using user root:
phantomjs /home/user/captureScreen.js "http://xx.xx.xx.xx/chart" "/home/user/07012014050636114.png"
I believe there is no need to share the JS code since it's working fine from the command line.
The problem is that when I run the same command from the web-app (Grails), it just returns with a 0 value, which tells me everything ran fine, but it's not creating the PNG file neither returning an error.
I'm calling the command from Groovy, this way:
String path = "phantomjs pathToJs.... etc"
def process = path.execute()
process.waitForOrKil(5000) // This runs in 1 to 2 seconds in the command line
println process.exitValue()
I tried adding write permissions to the tomcat7 user to the folder where the JS file and where the image is written but still it didn't work but I still believe it's something related to permissions
Any thoughts?
Thanks!
As for command execution, we experienced problem in Grails applications concerning pure string notation. Using the array syntax
["/usr/binphantom/js","/home/user/captureScreen.js","http://xx.xx.xx.xx/chart","/home/user/07012014050636114.png"].execute()
made the thing work. I think it has to do with shell expansion which differs on how strings are handled in Groovy.
Related
I'm currently working on a project with Electron 9.0.4 and Electron-Builder 22.8.0 and am faced with a problem that doesn't seem too difficult but there isn't a valid solution online! (At least I couldn't find it)
I have my main program that does all of the UI tasks, and a command line script that does some backend. The reason I have this command line script is so that I can run certain parts of the application without opening the window itself. Everything works fine on my computer. After running npm link, my CL script is added to my environment variables and I can just run it from the console. However, when I try to build with electron-builder, the problem occurs.
If I use my Setup.exe on another computer, the command line script just won't be added to the environment variables and I couldn't find instructions on how to do this in the electron, nodejs, or electron-builder documentation. What I found was a suggestion on another question to add npm -g install as a post-install script, but that had no effect either.
Someone else suggested adding npm link as a post-installation script, but firstly if I am not mistaken this function is not intended for production and secondly it created an infinite loop as npm link triggered the post-installation script over and over again.
Thats how the script is added to the project
"bin": {
"command-name": "/cl.js"
}
Any help is appreciated!
Since I couldn't find a direct solution to my problem and didn't want to look any further for a solution while being able to take a different approach.
I decided to take a step back and look for another method to solve my problem I came to the conclusion that I didn't really need to add a script to the command line. My solution was to look for a certain argument when starting the regular application.
if (process.argv.includes("cli")) { /* Do commandline stuff */ }
When the custom argument is found, I simply run the script that should've been run from the command line. Using this approach, you can create a shortcut to my executable that contains the custom argument and then instead of the application it runs the command line script.
Im trying to run a .bat file on my server through php popen command, ive struggled and finally got to the point where all the permissions are set correctly and now i can actually execute the file but i have a problem. In my server logs it displays
foo.bat: line 1: mstsc: command not found, referer: http://dev.example.com
The full code in the file is mstsc /v:192.168.1.1 I know this means that it doesn't recognise the command on centos but im not sure what to do to fix the problem.
The aim of this code is to open RDP for the user who requested it. Bear in mind that this code works perfectly locally on my windows OS using xampp but when i upload it to the server running CENTOS it doesnt work.
My question is
How do i fix this error and allow CENTOS to execute a command that opens an RDP window for the user
MSTSC is a Windows RDP client which is why it works on Windows.
It's not available to run on CentOS, let alone call by executing a Windows batch file! You'll need to use an alternative solution like FreeRDP and use a script like this one if you want to do this from CentOS: https://www.server-world.info/en/note?os=CentOS_7&p=x&f=5
I feel like this is exactly what you're after
http://www.jjclements.co.uk/2010/02/21/rdp-hyperlink/
It allows you run a bat file that opens windows RDP without needing to write a single line of server code. Take a look its pretty good!
How do I start a node.js script and still be able to execute commands into the terminal ? I am looking for a node.js REPL that is also there for my custom script, so that I can inspect/log the state of my program for instance.
This is something similar to this JVM question, but for node.js.
I have tried node -i server.js without results. Do I need to have custom code in my script or is it feasible without that ? I saw this post, but it requires custom code, which I'd like to avoid.
Also, bonus points for reattaching a node script launched by an init script (I can see it in the process list : node -i server.js).
You can start a repl loop from within your program
http://nodejs.org/api/repl.html
Does the other way round work for you?
Start the REPL and then load the script and then execute your commands. Use load to load your script.
Inside REPL, try
.load server.js
I installed sqlite3 like this:
npm install sqlite3
It succeded without any errors. Now, if I want to execute sqlite, I get the Following Exception:
It says "'module' is undefined". Am I missing something? I tried the exact same thing on OpenSUSE and it worked as expected.
The first problem is you're trying to run a node.js script using Windows' JScript implementation (this is the default file association in Windows). You need to run the script with node in one way or another. One way to do this is via the command prompt with node myscript.js.
The second problem is that you're trying to execute sqlite3.js which doesn't actually do anything except export the database client. Instead you need to write your own script (that lives in the parent directory of node_modules) that require()'s sqlite3 and uses that.
A simple question: Is it possible to configure the Geany IDE so that Node.js servers can be run directly from Geany using the "Run" button?
When inside a JS file, go to Build > Set Build Commands, there should be a section title Execute commands. To use node to execute your files, put: node "%f" in the "Execute" command textbox.
When you change this, any .js files you are editing will run node in the virtual terminal when you hit F5.
If you want to set up an entire project to run the server whenever you're working somewhere within a given directory structure, you'll have to mess with project-level configuration. (something I don't usually bother with) My solution here just gives you a quick way to execute a single JS file without using an external terminal.
UPDATE: node "%f" seems to be legacy, but nodejs "%f" works