We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › exec() won't exec()
Page Index Toggle Pages: 1
exec() won't exec() (Read 1114 times)
exec() won't exec()
Sep 27th, 2006, 3:07am
 
hi,
I'm trying to do the following in OSX:

try {
 Runtime.getRuntime().exec("ls ~/Desktop > ~Desktop/listing.txt");
} catch(IOException ioe) {
 ioe.printStackTrace();
 println("no can do");
}

This doesn't throw an exception, but it also doesn't visibly do anything (e.g., create the file it's supposed to create). It works fine from the command line. Any suggestions?

thanks!
Re: exec() won't exec()
Reply #1 - Sep 27th, 2006, 9:46pm
 
the ~ is specific to the shell, and without a shell to interpret it, runtime.exec prolly won't work. i'd use full paths. i.e. System.getProperty("user.home") + "/Desktop". i'm not sure if > will work either, since that's also part of the shell, but i'm not sure at what level it's interpreted. much hunch is that > will work but ~ will not with exec().
Re: exec() won't exec()
Reply #2 - Oct 3rd, 2006, 11:02pm
 
Interesting. It turns out that both ~ and > fail silently, but

Runtime.getRuntime().exec("cp /Users/neil/Desktop/foo /Users/neil/Desktop/foo2");

is fine. Any thoughts on how to get a listing of a directory into a file or into a String[] without using > ?

thanks,
neil
Page Index Toggle Pages: 1