|
Hi All,
I need to invoke native command and show its results in the page of a grails application. Here is what I did: 1. create a simple helloworld grail application 2. modify helloController.groovy: package helloworld class HelloController { def cmd = "cmd /c dir" def result def word = { result = cmd.execute().text render cmd } } 3. run grails application But an exception is thrown. It can not show the result I expected. Why? In this case, I just want to show dir command result in the web page. How can I do this kind of job in grails? Say, the result of linux command such as 'ls', 'df', etc Many thanks. |
|
Hi,
what does the exception say? I would guess, that the command is not found. Your Grails app does not necessarily inherit your environment, i.e. the PATH might not be set or set differently. You might need to use absolut paths. Did you also try "cmd.exe /c dir"? Wolfgang |
|
import java.io.*;
class HelloController { def cmd = "dir c:" def result def word = { String line Process p = Runtime.getRuntime().exec(cmd) render cmd } } 2010/11/18 Wolfgang Schell <[hidden email]>: > > Hi, > > what does the exception say? I would guess, that the command is not found. > Your Grails app does not necessarily inherit your environment, i.e. the PATH > might not be set or set differently. You might need to use absolut paths. > Did you also try "cmd.exe /c dir"? > > Wolfgang > -- > View this message in context: http://grails.1312388.n4.nabble.com/How-to-invoke-native-command-in-Grails-tp3048037p3048211.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- SammyRulez http://www.sammyrulez.com http://twitter.com/sammyrulez http://www.linkedin.com/in/sammyrulez --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
import java.io.*;
class HelloController { def cmd = "dir c:" def result def word = { def String line def out = "" Process p = Runtime.getRuntime().exec(cmd) BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { out = "${out}\n${line}" } input.close(); render cmd } } 2010/11/18 ::SammyRulez:: <[hidden email]>: > import java.io.*; > > class HelloController { > def cmd = "dir c:" > > def result > def word = { > String line > Process p = Runtime.getRuntime().exec(cmd) > > > render cmd > } > > } > > > > 2010/11/18 Wolfgang Schell <[hidden email]>: >> >> Hi, >> >> what does the exception say? I would guess, that the command is not found. >> Your Grails app does not necessarily inherit your environment, i.e. the PATH >> might not be set or set differently. You might need to use absolut paths. >> Did you also try "cmd.exe /c dir"? >> >> Wolfgang >> -- >> View this message in context: http://grails.1312388.n4.nabble.com/How-to-invoke-native-command-in-Grails-tp3048037p3048211.html >> Sent from the Grails - user mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> > > > > -- > SammyRulez > http://www.sammyrulez.com > http://twitter.com/sammyrulez > http://www.linkedin.com/in/sammyrulez > -- SammyRulez http://www.sammyrulez.com http://twitter.com/sammyrulez http://www.linkedin.com/in/sammyrulez --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
