Java Fetch Process Path method

Source: Internet
Author: User

1, use current path

Execute Java command before the CD enters the directory where the Java command is located, the program should be the system Properties user.dir or through the new File (".") Fetch path

2, use relative path

System.getenv ("Java_home")/bin/java.exe

3, increase environment variable

Before executing JAVA, Add an environment variable to the bat or shell, and under Unix remember export

//windows:set proc_path=d:\jdk1.6.0_18\bin\javaw.exe

//unix:    export proc_path=d:\jdk1.6.0_18\bin\javaw.exe

System.out.println (system.getenv ("Proc_path"));

4, SIGAR process path based on process ID

/*1), taking the current process Id*///[email protected] [email  protected] Computer name String pid = managementfactory.getruntimemxbean (). GetName ();//@ before the process Idpid  = pid.substring (0, pid.indexof (' @ ')),/*2), process command path based on process ID  d:\jdk1.6.0_18\bin\javaw.exe*/ Sigar sigar = new sigar ();//http://www.oschina.net/p/sigarsystem.out.println ( Sigar.getprocexe (PID). GetName ()); System.out.println (Sigar.getprocargs (PID) [0]); 


Java Fetch process path method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.