Java executes the method of Windows cmd command _java

Source: Internet
Author: User
Tags garbage collection memory usage nslookup disk defragmenter

This article illustrates the Java method for executing the cmd command under Windows. Share to everyone for your reference.

The specific implementation code is as follows:

Copy Code code as follows:
Get run time
Runtime RT = Runtime.getruntime ();
Get process
Process P = rt.exec (string[] cmdarray);//or process P = rt.exec (String cmd);
If p is not empty, then empty
if (null!=p) {destory
P.destory ();
P=null;
}

For example:

Copy Code code as follows:
Runtime RT = Runtime.getruntime ();
Process p = rt.exec ("cmd.exe/c shutdown-a");
System.out.println (P.tostring ());

cmd/c dir closes the command window after the dir command has been executed.

cmd/k dir does not close the command window until the dir command is executed.

cmd/c start dir opens a new window and executes the dir instruction, and the original window closes.

cmd/k start dir opens a new window and executes the dir instruction, and the original window does not close.

can use cmd/? To view help information.

Add:

★CMD Command ★
1. Gpedit.msc-----Group Policy
2. Sndrec32-------Recorder
3. Nslookup-------IP Address detector
4. Explorer-------Open Explorer
5. Logoff---------Cancellation Order
6. Tsshutdn-------60-second Countdown shutdown command
7. Lusrmgr.msc----native Users and Groups
8. Services.msc---Local Service settings
9. oobe/msoobe/a----Check to see if XP is active
Notepad--------Open the Notebook
cleanmgr-------Garbage collection.
A. Net start messenger----begin the Messenger service
Compmgmt.msc---Computer Management
net stop Messenger-----stopping messenger Service
Conf-----------start NetMeeting
Dvdplay--------DVD Player
Charmap--------Start character mapping table
Diskmgmt.msc---Disk Management utility
Calc-----------Start Calculator
Dfrg.msc-------Disk Defragmenter
Chkdsk.exe-----CHKDSK disk Check
Devmgmt.msc---Device Manager
regsvr32/u *.dll----Stop DLL file from running
DRWTSN32------System Doctor
Rononce-p----15-second shutdown
DxDiag---------Review DirectX Information
Regedt32-------Registry Editor
Msconfig.exe---System Configuration Utility
Rsop.msc-------Group Policy result set
Mem.exe--------Show Memory usage
Regedit.exe----Registration Form
Winchat--------XP with LAN Chat
ProgMan--------Program Manager
WINMSD---------System Information
PERFMON.MSC----Computer Performance monitoring Program
Winver---------Check the Windows version
Sfc/scannow-----Scan Error and recover
Taskmgr-----Task Manager (2000/xp/2003
Winver---------Check the Windows version
Wmimgmt.msc----Open Windows Management Architecture (WMI)
Wupdmgr--------Windows Update
wscript--------Windows Script Host Settings
Write----------WordPad
WINMSD---------System Information
Wiaacmgr-------Scanner and Camera Wizard
Winchat--------XP with LAN Chat
Mem.exe--------Display Memory usage
Msconfig.exe---System Configuration Utility
Mplayer2-------Simple widnows Media Player
MSPaint--------Drawing Board
MSTSC----------Remote Desktop Connection
Mplayer2-------Media Player
Magnify--------Magnifier Utility
MMC------------Open the console
Mobsync--------Sync Command
DxDiag---------Check DirectX information
DRWTSN32------System Doctor
Devmgmt.msc---Device Manager
Dfrg.msc-------Disk Defragmenter
Diskmgmt.msc---Disk Management utility
DCOMCNFG-------Open System Component Services
DdeShare-------open DDE Share settings
Dvdplay--------DVD Player
The. net stop Messenger-----Stop messenger Service
Start Messenger Service with the. Net start Messenger----
Notepad--------Open
nslookup-------Network Management Tools Wizard
ntbackup-------system backup and restore
Narrator-------Screen "narrator"
Ntmsmgr.msc----Mobile Storage Manager
Ntmsoprq.msc---Mobile Storage Administrator action Request
Netstat-an----(TC) command Check interface
Syncapp--------Create a Briefcase
Sysedit--------System Configuration Editor
Sigverif-------File Signature Verification program
Sndrec32-------Recorder.
SHRPUBW--------Create a shared folder
Secpol.msc-----Local Security Policy
SYSKEY---------System encryption, once encrypted can not be undone, protect the Windows XP system dual Password
Services.msc---Local Service settings
BA Sndvol32-------Volume Control program
Sfc.exe--------System File Checker
Sfc/scannow---Windows File Protection
TSSHUTDN-------60-second Countdown shutdown command
Tourstart------XP Introduction (roaming XP programs that appear after installation is complete)
Taskmgr--------Task Manager
EVENTVWR-------Event Viewer
Eudcedit-------Word-formation program
-------Explorer Opens
Packager-------Object Wrapping procedure
PERFMON.MSC----Computer Performance monitoring Program
ProgMan--------Program Manager
Regedit.exe----Registration Form
Rsop.msc-------Group Policy result set
Regedt32-------Registry Editor
Rononce-p----15 seconds off.
regsvr32/u *.dll----Stop DLL file from running
regsvr32/u zipfldr.dll------Cancel Zip support
Cmd.exe--------cmd command prompt
Chkdsk.exe-----CHKDSK disk Check
Certmgr.msc----Certificate Management Utility
102. Calc-----------Start Calculator
Charmap--------Start character mapping table
CLICONFG-------SQL SERVER Client Network Utility
CLIPBRD--------Clipboard Viewer
A. conf-----------start NetMeeting
Compmgmt.msc---Computer Management
108. cleanmgr-------Garbage Collection
109. Ciadv.msc------Indexing Service Program
Osk------------turn on on-screen keyboard
ODBCAD32-------ODBC data Source Manager
112. oobe/msoobe/a----Check to see if XP is active
113. Lusrmgr.msc----native Users and Groups
114. Logoff---------Logoff command
IExpress-------Trojan Bundle tools, the system with its own
116. Nslookup-------IP Address Detectors
117. Fsmgmt.msc-----shared Folder Manager
118. Utilman--------Utility Manager
119. Gpedit.msc-----Group Policy
Explorer-------Open Resource Manager
Javac actually executed just no output execution result because you don't have the part that outputs the execution result
If you execute

Copy Code code as follows:
Runtime.getRuntime.exec ("cmd");

I can't see the results.
Because it does not execute in the Java program but on the operating system.
You can do this.
Copy Code code as follows:
Runtime.getRuntime.exec ("cmd/c start Javac");

You can see a command line window.

I hope this article will help you with your Java programming.

Related Article

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.