• Post Reply Bookmark Topic Watch Topic
  • New Topic

how do i execute system calls in java  RSS feed

 
krishna balaji
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the function in java to call system calls ?
what package should be imported to use it?

thank you
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can execute external programs using Runtime.exec
 
krishna balaji
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test
{
public static void main(String args[])
{
Runtime.exec("dir>a.txt");
}
}
i complied this progra got the error:

on-static method exec(java.lang.String) cannot be referenced from a static context
Runtime.exec("dir>a.txt");

whats wrong here ?
 
Joe Ess
Bartender
Posts: 9441
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exec() is not a static method. You need to obtain an instance of Runtime.
 
krishna balaji
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks lot friends i got wat i wanted
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!