Rabu, 04 Januari 2012

Bact File

Pada DOS , OS / 2 , dan Microsoft Windows , sebuah file batch adalah file teks yang berisi serangkaian perintah yang dimaksudkan untuk dieksekusi oleh command interpreter . Similar to job control language and other systems on mainframe and minicomputer systems, batch files were added to ease the work required for certain regular tasks by allowing the user to set up a batch script to automate many commands. Mirip dengan kontrol bahasa pekerjaan dan sistem lain pada sistem komputer mini dan mainframe, file batch yang ditambahkan untuk mempermudah kerja yang dibutuhkan untuk tugas-tugas rutin tertentu dengan memungkinkan pengguna untuk membuat batch script untuk mengotomatisasi banyak perintah. When a batch file is run, the shell program (usually COMMAND.COM or cmd.exe ) reads the file and executes its commands, normally line-by-line. Bila file batch dijalankan, shell program (biasanya COMMAND.COM atau cmd.exe ) membaca file dan mengeksekusi perintah-nya, biasanya baris demi baris. Batch files are useful for running a sequence of executables automatically and are often used to automate repetitive or tedious processes. [ 1 ] Unix-like operating systems (such as Linux ) have a similar type of file called a shell script . [ 2 ] Batch file berguna untuk menjalankan urutan executable secara otomatis dan sering digunakan untuk mengotomatisasi proses berulang-ulang atau membosankan. [1] Unix-seperti sistem operasi (seperti Linux ) memiliki tipe yang sama dari file disebut skrip shell . [2]
DOS batch files have the filename extension .bat . file batch DOS memiliki ekstensi nama file . kelelawar. Batch files for other environments may have different extensions, eg .cmd or .bat in the Microsoft Windows NT -family of operating systems and OS/2, or .btm in 4DOS and 4NT related shells. Batch file untuk lingkungan lain mungkin memiliki ekstensi yang berbeda, misalnya atau. Cmd. Pemukul di Microsoft Windows NT keluarga-sistem operasi dan OS / 2, atau. BTM di 4DOS dan 4NT kerang terkait. The Windows 9x family of operating systems only recognize the .bat extension. The Windows 9x keluarga sistem operasi hanya mengakui. ekstensi bat. In OS/2 a file with a .cmd extension can also be a Rexx file. Dalam OS / 2 file dengan ekstensi cmd. Juga bisa menjadi Rexx file.

Varian

In MS-DOS, a batch file can be started from the command line by typing its name (along with any required parameters) and pressing the "enter" key. Pada MS-DOS, sebuah file batch bisa dimulai dari baris perintah dengan mengetik nama (bersama dengan parameter yang diperlukan) dan menekan "enter" key. When MS-DOS loads, the file AUTOEXEC.BAT is automatically executed, so any commands that need to be run to set up the MS-DOS environment for use could be placed in this file. Ketika MS-DOS beban, file AUTOEXEC.BAT secara otomatis dijalankan, sehingga setiap perintah yang perlu dijalankan untuk mendirikan lingkungan MS-DOS untuk digunakan dapat ditempatkan dalam file ini. Computer users would have the autoexec file set up the system date and time, initialize the MS-DOS environment, load any resident programs or device drivers, or initialize network connections and assignments. Pengguna komputer akan memiliki file autoexec mengatur sistem tanggal dan waktu, menginisialisasi lingkungan MS-DOS, load program penduduk atau device driver, atau menginisialisasi koneksi jaringan dan tugas.

[ edit ] DOS [ sunting ] DOS

In MS-DOS , the extension ".bat" signified a file which could be executed by the command interpretor COMMAND.COM , by running line by line as if it was a list of commands to be entered, with some extra batch file specific commands for basic programming functionality, including a GOTO command for changing flow of line execution. Pada MS-DOS , ekstensi ". kelelawar" menandakan file yang dapat dieksekusi oleh interpretor perintah COMMAND.COM , dengan menjalankan baris demi baris seolah-olah itu adalah daftar perintah yang akan dimasukkan, dengan beberapa tambahan perintah batch file spesifik untuk fungsionalitas pemrograman dasar, termasuk GOTO perintah untuk mengubah aliran eksekusi baris.

Awal Windows

Microsoft Windows was introduced in 1985 as a GUI Operating System alternative to text-based operating and was designed to run on MS-DOS. Microsoft Windows diperkenalkan pada tahun 1985 sebagai GUI Sistem Operasi alternatif untuk-operasi berbasis teks dan dirancang untuk berjalan pada MS-DOS. In order to start it the WIN command was used and could be added to the end of the AUTOEXEC.BAT file to allow automatic loading of Windows. Dalam rangka untuk memulainya dengan WIN perintah yang digunakan dan dapat ditambahkan ke akhir AUTOEXEC.BAT file untuk memungkinkan loading otomatis Windows. In the earlier versions one could run a .bat type file from Windows in the MS-DOS Prompt. Dalam versi sebelumnya orang bisa menjalankan file bat. Jenis dari Windows di MS-DOS Prompt.
Windows was run from MS-DOS and used COMMAND.COM to run .bat files on the following operating systems : Windows dijalankan dari MS-DOS dan digunakan COMMAND.COM untuk menjalankan berikut. Kelelawar file pada sistem operasi :

OS / 2

The IBM OS/2 operating system supported DOS-style batch files. The IBM OS / 2 sistem operasi yang didukung gaya batch file-DOS. It also included a version of REXX , which was a more advanced batch file scripting language . Ini juga termasuk versi REXX , yang merupakan batch file yang lebih maju bahasa scripting . IBM and Microsoft started developing this system but during the construction of it broke up after a dispute, as a result of this IBM referred to their MS-DOS like console shell without mention of Microsoft; naming it just DOS, although this seemingly made no difference on the way batch files worked from COMMAND.COM. IBM dan Microsoft mulai mengembangkan sistem ini tetapi selama pembangunan itu bubar setelah sengketa, sebagai hasil dari IBM ini disebut-MS mereka DOS seperti konsol shell tanpa menyebutkan dari Microsoft, penamaan itu hanya DOS, meskipun hal ini tampaknya ada bedanya di batch file cara bekerja dari COMMAND.COM.
OS/2's batch file interpreter also supports an EXTPROC command. juru batch file OS / 2 juga mendukung perintah EXTPROC. This passes the batch file to the program named on the EXTPROC file as a data file. Ini melewati batch file untuk program bernama pada file EXTPROC sebagai file data. The named program can be a script file; this is similar to the various Unix #! Program bernama dapat berupa file skrip, ini mirip dengan berbagai Unix #! commands. perintah.

Windows NT

Windows versions other than the NT line of operating systems were run from MS-DOS and used the same command interpreter, COMMAND.COM , to execute batch files. versi Windows lainnya dari garis PB sistem operasi dijalankan dari MS-DOS dan menggunakan perintah yang sama interpreter, COMMAND.COM , untuk menjalankan file batch. However, the operating systems in the Windows NT series run directly from booting the hard drive and aren't based on MS-DOS. Namun, sistem operasi dalam Windows NT seri dijalankan langsung dari boot hard drive dan tidak didasarkan pada MS-DOS. In order to replace COMMAND.COM, cmd.exe was introduced which allowed execution of .cmd files as well as .bat files in the same way, and used slightly different commands than COMMAND.COM, meaning that the new cmd.exe was not backwards compatible with older batch files for use with COMMAND.COM. Dalam rangka untuk menggantikan COMMAND.COM, cmd.exe diperkenalkan yang memungkinkan pelaksanaan file cmd serta.. Bat file dengan cara yang sama, dan digunakan perintah sedikit berbeda dari COMMAND.COM, yang berarti bahwa cmd.exe baru tidak kompatibel dengan file batch yang lebih tua untuk digunakan dengan COMMAND.COM.
Microsoft released a version of cmd.exe for Windows 9x and ME called WIN95CMD to allow users of older versions of Windows to use certain cmd.exe-style batch files. Microsoft merilis sebuah versi cmd.exe untuk Windows 9x dan ME disebut WIN95CMD untuk memungkinkan pengguna versi Windows untuk menggunakan file-file tertentu cmd.exe batch-gaya.
Currently, cmd.exe is the command interpreter for batch files on the latest version of Windows. Saat ini, cmd.exe adalah command interpreter untuk file batch pada versi terbaru Windows.

ekstensi Filename

  • .bat : The first extension used by Microsoft for batch files. :. Kelelawar perpanjangan pertama kali digunakan oleh Microsoft untuk file batch. This extension runs with MS-DOS and all versions of Windows, under COMMAND.COM or cmd.exe, despite the different ways the two command interpreters execute batch files. Ekstensi ini berjalan dengan MS-DOS dan semua versi Windows, di bawah COMMAND.COM atau cmd.exe, meskipun cara yang berbeda dengan dua penerjemah perintah mengeksekusi file batch.
  • .cmd : The extension used by operating systems in the Windows NT family and sent to cmd.exe for interpretation. :. Cmd Perpanjangan digunakan oleh sistem operasi dalam keluarga Windows NT dan dikirim ke cmd.exe untuk interpretasi. It does not work on computers relying on COMMAND.COM so prevents cmd.exe scripts from being executed in the wrong Windows environment. Ini tidak bekerja pada komputer mengandalkan COMMAND.COM sehingga mencegah script cmd.exe dari dieksekusi dalam lingkungan Windows yang salah. It is also used by IBM's OS/2 for batch files. Ia juga digunakan oleh IBM OS / 2 untuk file batch.
  • .btm : The extension used by 4DOS and 4NT . :. BTM Perpanjangan digunakan oleh 4DOS dan 4NT . The scripts run on 4DOS and 4NT are faster, especially with longer ones, as the script is loaded entirely ready for execution, rather than line-by-line. [ 3 ] Script berjalan di 4DOS dan 4NT lebih cepat, terutama dengan yang lebih lama, seperti script dimuat sepenuhnya siap untuk eksekusi, bukan baris-baris oleh. [3]

Perbedaan antara dan. cmd. bat eksekusi dalam keluarga Windows NT

The only known difference between .cmd and .bat file execution is that in a .cmd file the ERRORLEVEL variable changes even on a successful command that is affected by Command Extensions (when Command Extensions are enabled), whereas in .bat files the ERRORLEVEL variable changes only upon errors. [ 4 ] Tersebut dikenal satunya perbedaan antara dan. Cmd. Bat file eksekusi adalah bahwa dalam sebuah. Cmd file ERRORLEVEL bahkan pada sukses perintah yang dipengaruhi oleh Command Extensions ketika (Command Ekstensi diaktifkan adalah), sedangkan pada. kelelawar file perubahan variabel ERRORLEVEL variabel perubahan hanya pada kesalahan. [4]

Contoh

This example batch file is a simple program that displays a hello world program and then waits for the user to press a key before ending. Batch file ini contoh adalah sebuah program sederhana yang menampilkan program halo dunia dan kemudian menunggu pengguna untuk menekan tombol sebelum mengakhiri.
@ ECHO off @ ECHO off
ECHO Hello World! ECHO Hello World!
PAUSE JEDA
ECHO on ECHO pada
To execute the file it must be saved with a .bat or .cmd extension in plain text format (with a program like Notepad ). Untuk mengeksekusi file itu harus disimpan dengan atau. Bat ekstensi cmd. Dalam format teks biasa (dengan program seperti Notepad ).

Hasil

When executed (either from Windows Explorer or Command Prompt ) this is displayed: Ketika dilakukan (baik dari Windows Explorer atau Command Prompt ) ini ditampilkan:
Hello World! Hello World!
Press any key to continue . Tekan sembarang tombol untuk melanjutkan. . . . .

Penjelasan

The interpreter executes each line in turn, starting with the first. penerjemah mengeksekusi setiap baris pada gilirannya, dimulai dengan yang pertama. The @ symbol at the start of the line turns off the prompt from displaying for that command. The @ simbol pada awal baris mematikan prompt dari menampilkan untuk perintah itu. The command ECHO off turns off the prompt permanently, or until it is turned on again. Perintah ECHO off mematikan prompt permanen, atau sampai dihidupkan lagi. Then the next line is executed, the ECHO Hello World! command outputs Hello World! , as only off and on have special functions. Kemudian baris berikutnya dijalankan, ECHO Hello World! output perintah Hello World! , karena hanya off dan on memiliki fungsi khusus. Then the next line is executed, the PAUSE command literally 'pauses' the script's execution, and displays the output Press any key to continue . . . Kemudian baris berikutnya dijalankan, PAUSE perintah harfiah 'berhenti' script's eksekusi, dan menampilkan output Press any key to continue . . . Press any key to continue . . . Press any key to continue . . . . Press any key to continue . . . . After a key is pressed, the script continues onto the next line, ECHO on , which turns the prompt back on for use. Setelah tombol ditekan, script berlanjut ke baris berikutnya, ECHO on , yang mengubah kembali prompt untuk digunakan. Then the end of the script is reached so execution stops. Kemudian akhir naskah tercapai begitu berhenti eksekusi. If the script started from the Command Prompt , then it will remain open at the prompt. Jika script mulai dari Command Prompt , maka akan tetap terbuka pada prompt. If the script started from Windows Explorer , then upon finishing the window will close. Jika script mulai dari Windows Explorer , kemudian setelah menyelesaikan jendela akan ditutup.

contoh batch Advanced - shutdown bersyarat

@ echo off @ Echo off
color 3 warna 3
title Conditional Shutdown judul Bersyarat Shutdown
set /p name=enter a name: set / p name = masukkan nama:
: start : Mulai
cls cls
echo Hi, % name % echo Hi,%% nama
echo . echo. 
echo 1.Shutdown echo 1.Shutdown
echo 2.Quit echo 2.Quit
set /p choice=enter your choice 1,2: set / p = masukkan pilihan Anda 1,2 pilihan: 
if % choice % ==1 goto shutdown jika% pilihan% == 1 goto shutdown
if % choice % ==2 exit jika%% pilihan == 2 keluar
 
: shutdown : Shutdown
cls cls
set /p sec=enter the number of seconds that you wish the computer to shutdown in : set / p detik = masukkan jumlah detik yang Anda ingin komputer untuk shutdown dalam: 
set /p msg=enter the shutdown message you wish to display: set / p msg = masukkan pesan shutdown yang ingin Anda tampilkan: 
shutdown -s -f -t % sec % -c " % msg % " -S-f-t% shutdown detik-% c "% msg%"
echo shutdown initiated at % time % echo shutdown dimulai pada saat%%
set /p cancel=type cancel to stop shutdown set / p membatalkan = tipe membatalkan untuk menghentikan shutdown 
if % cancel % ==cancel shutdown -a jika% membatalkan% == membatalkan shutdown-a
if % cancel % ==cancel goto start jika% membatalkan% == membatalkan mulai goto

Keterbatasan / Pengecualian

Null values in variables Nilai Null dalam variabel

Some commands can fail syntactically and terminate the script, if the variables in the command contain a null value. Beberapa perintah bisa gagal sintaktis dan menghentikan skrip, jika variabel dalam perintah berisi nilai null. For example this test will only work properly only if the value of %foo% is 1 character or greater: Misalnya tes ini hanya akan bekerja dengan benar hanya jika nilai dari%% foo adalah 1 karakter atau lebih:
IF % foo % ==bar ECHO Correct. JIKA%% foo bar == ECHO benar.
But if the value of %foo% is null, the command will evaluate as an invalid command: Tetapi jika nilai dari%% foo adalah null, perintah akan mengevaluasi sebagai perintah tidak valid:
IF ==bar ECHO Correct. JIKA == bar ECHO benar.

The typical way to deal with this is to always enclose the tested variables in quotes, or include some other unchanging character on both sides of the evaluation. Cara khas untuk mengatasi hal ini adalah selalu menyertakan variabel yang diuji dalam tanda kutip, atau memasukkan beberapa karakter tidak berubah lain di kedua sisi evaluasi. For example, these tests are syntactically correct and evaluate as False if %foo% contains a null value: Misalnya, tes ini sintaksis benar dan evaluasi sebagai salah jika% foo% berisi nilai null:
IF " % foo % "=="bar" ECHO Correct. JIKA "%% foo" == "bar" ECHO Benar.
IF 1 % foo % ==1bar ECHO Correct. JIKA foo%% 1 == 1bar ECHO benar.
A null value in %foo% results in the commands being parsed as: Sebuah nilai null dalam hasil%% foo dalam perintah yang diuraikan sebagai:
IF ""=="bar" ECHO Correct. JIKA bar ""==" "ECHO Benar.
IF 1==1bar ECHO Correct. JIKA 1 1bar == ECHO benar.

Kutipan dan spasi dalam string berlalu

  • For some commands, spaces are treated as delimiters in commands, unless those spaces are enclosed by quotes. Untuk beberapa perintah, spasi diperlakukan sebagai pembatas dalam perintah, kecuali mereka spasi diapit oleh tanda kutip.
  • For other commands, spaces are not treated as delimiters and don't need quotes. Untuk perintah lain, spasi tidak diperlakukan sebagai pembatas dan tidak perlu tanda kutip.
This can cause conflicts where a string contains quotes, and is to be inserted into another line of text that must also be enclosed in quotes, such as a file name with spaces: Hal ini dapat menyebabkan konflik di mana string berisi tanda kutip, dan akan dimasukkan ke baris lain teks yang juga harus diapit dalam tanda kutip, seperti nama file dengan spasi:
set foo="this string is enclosed in quotes" set foo = "string ini ditutup dengan tanda kutip"
 
echo "test 1 % foo % " echo "1 foo%% tes"
"test 1 "this string is enclosed in quotes"" "Test 1" string ini ditutup dengan tanda kutip ""
 
echo test > "test 1 % foo % " tes echo> "1 foo%% tes"
dir test* /b dir test * / b
test 1 this tes 1 ini
While the extended syntax handling of Windows XP allows for quote stripping, this is not helpful where the quotes are to be passed as part of a description: Sementara penanganan sintaks diperpanjang Windows XP memungkinkan untuk kutipan pengupasan, hal ini tidak membantu mana tanda kutip harus lulus sebagai bagian dari uraian:
set src=logon-script.bat set src = logon-script.bat
set cm=net use p: "\\file\data\accounts\students-11\profiles\ % username % " set cm = p net use: "\ \ file \ data \ account \ siswa-11 \ profil \%% username"
% cm % %% Cm
set err= % errorlevel % set err =%% ERRORLEVEL
if % err % == 0 ( jika% err% == 0 (
  eventcreate /ID 997 /L SYSTEM /T INFORMATION /SO " % src % " /d "Command successful: % cm % " eventcreate / ID 997 / L SISTEM / T INFORMASI / SO "% src%" / d "Perintah yang sukses:% cm%"
) ELSE ( ) LAIN (
  eventcreate /ID 998 /L SYSTEM /T WARNING /SO " % src % " /d "Error % err % for command: % cm % " eventcreate / ID 998 / L SISTEM / T PERINGATAN / SO "% src%" / d "% Kesalahan err% untuk perintah: cm%%"
) )
The description for the EventCreate event is parsed as: Deskripsi untuk acara EventCreate diparse sebagai:
"Command successful: net use p: "\\file\data\accounts\students-11\profiles\JSmith"" "Perintah sukses: p net use:" \ \ file \ data \ account \ siswa-11 \ profil \ JSmith ""
which results in a batch file syntax error: yang menghasilkan kesalahan sintaks file batch:
ERROR: The parameter is incorrect. ERROR: Parameter tidak benar.
There is no fix for this quote handling problem. Tidak ada untuk memperbaiki masalah ini penanganan kutipan.

Future Masa Depan

Microsoft has not officially released information pertaining to the future of Command Prompt (host for .bat and .cmd files) yet, but the company is now starting to include Windows PowerShell in releases for newer operating systems , which has all the core functions of Command Prompt and more (and instead of .bat and .cmd files, it runs .ps1 files). Microsoft belum resmi dirilis informasi yang berhubungan dengan masa depan Command Prompt (host untuk dan. kelelawar. file cmd) belum, tetapi perusahaan tersebut sekarang mulai untuk memasukkan Windows PowerShell di rilis untuk baru sistem operasi , yang memiliki semua fungsi inti dari Komando Prompt dan lebih (dan bukan kelelawar dan.. file cmd, itu berjalan. PS1 file). Yet it is important to remember that it is not certain this will replace Command Prompt, and that Microsoft is still making important tools for Command Prompt specifically, instead of for PowerShell (such as servermanagercmd.exe , which incorporates the entire set of Server Manager functions for Windows Server 2008 ). [ 5 ] Namun penting untuk diingat bahwa itu tidak ada kepastian ini akan menggantikan Command Prompt, dan bahwa Microsoft masih membuat alat penting untuk Command Prompt khusus, bukan untuk PowerShell (seperti servermanagercmd.exe , yang mencakup seluruh himpunan fungsi Server Manager untuk Windows Server 2008 ). [5]

Windows lainnya bahasa scripting

In addition to traditional batch files, the need for more powerful capabilities has led to the development of other Windows-specific scripting languages: Selain file batch tradisional, kebutuhan akan kemampuan yang lebih kuat telah menyebabkan perkembangan bahasa scripting lain Windows-spesifik:
  • .kix : KiXtart was developed by a Microsoft employee in 1991, specifically to meet the need for commands useful in a network logon script while retaining the simple 'feel' of the traditional batch file. :. Kix KiXtart dikembangkan oleh seorang karyawan Microsoft pada tahun 1991, khusus untuk memenuhi kebutuhan untuk perintah yang berguna dalam logon script jaringan sementara tetap mempertahankan merasa 'sederhana' dari file batch tradisional.
  • .vbs and .js : Released in 1998, Windows Script Host (consisting of cscript.exe and wscript.exe) runs scripts written in VBScript or JScript . :. Vbs dan js. Dirilis pada tahun 1998, Windows Script Host (terdiri dari cscript.exe dan wscript.exe) berjalan script ditulis dalam VBScript atau JScript . It can run them in windowed mode (with the wscript.exe host) and console-based mode (with the cscript.exe host). Hal ini dapat menjalankan mereka dalam mode windowed (dengan host wscript.exe) dan modus konsol berbasis (dengan host cscript.exe). They have been a part of Windows since Windows 98 . Mereka telah menjadi bagian dari Windows sejak Windows 98 .
  • .ps1 : In 2006, Microsoft released a further raw-text script processor, Windows PowerShell , which can be used with Windows XP (SP2/SP3) and above. :. PS1 Pada tahun 2006, Microsoft merilis sebuah prosesor mentah-text script lebih lanjut, Windows PowerShell , yang dapat digunakan dengan Windows XP (SP2/SP3) dan di atas. This is designed for both interactive use from a command line interface, and also for writing scripts, and has a strong resemblance to Unix shells. [ 6 ] Ini dirancang untuk keduanya menggunakan interaktif dari antarmuka baris perintah, dan juga untuk menulis skrip, dan memiliki kemiripan kuat untuk Unix shell. [6]
In addition to these, powerful cross-platform scripting tools such as Perl , Python , Ruby and Rexx are now available for Windows. Selain itu, kuat cross-platform scripting alat seperti Perl , Python , Ruby dan Rexx sekarang tersedia untuk Windows.
If the appropriate extension is set in the PATHEXT environment, the file will run without need of typing in the extension. Jika ekstensi yang sesuai diatur dalam lingkungan PATHEXT, file tersebut akan berjalan tanpa perlu mengetik di ekstensi.
 
Previous Post
Next Post

0 komentar:

Trimakasih atas kunjunganya