Condividi tramite


call

Chiama un programma batch da un altro senza arrestare il programma batch padre. The call command accepts labels as the target of the call.

Note

La chiamata non ha alcun effetto al prompt dei comandi quando viene usata all'esterno di uno script o di un file batch.

Syntax

call [drive:][path]<filename> [<batchparameters>]] 
call [:<label> [<arguments>]]

Parameters

Parameter Description
[<drive>:][<path>]<filename> Specifica il percorso e il nome del programma batch che si desidera chiamare. Il <filename> parametro è obbligatorio e deve avere un'estensione .bat o .cmd.
<batchparameters> Specifica le informazioni della riga di comando richieste dal programma batch.
:<label> Specifica l'etichetta a cui si vuole passare un controllo programma batch.
<arguments> Specifica le informazioni della riga di comando da passare alla nuova istanza del programma batch, a partire da :<label>.
/? Visualizza la guida al prompt dei comandi.

Batch parameters

The batch script argument references (%0, %1, ...) are listed in the following tables.

Using the %* value in a batch script refers to all the arguments (for example, %1, %2, %3...).

You can use the following optional syntaxes as substitutions for batch parameters (%n):

Batch Parameter Description
%~1 Expands %1 and removes surrounding quotation marks.
%~f1 Expands %1 to a fully qualified path.
%~d1 Expands %1 to a drive letter only.
%~p1 Expands %1 to a path only.
%~n1 Expands %1 to a file name only.
%~x1 Expands %1 to a file name extension only.
%~s1 Expands %1 to a fully qualified path that contains short names only.
%~a1 Expands %1 to the file attributes.
%~t1 Expands %1 to the date and time of file.
%~z1 Expands %1 to the size of the file.
%~$PATH:1 Searches the directories listed in the PATH environment variable, and expands %1 to the fully qualified name of the first directory found. Se il nome della variabile di ambiente non è definito o il file non viene trovato dalla ricerca, questo modificatore si espande alla stringa vuota.

La tabella seguente illustra come combinare i modificatori con i parametri batch per i risultati composti:

Parametro batch con modificatore Description
%~dp1 Expands %1 to a drive letter and path only.
%~nx1 Expands %1 to a file name and extension only.
%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %1, and then expands to the drive letter and path of the first directory found.
%~ftza1 Expands %1 to display output similar to the dir command.

In the above examples, %1 and PATH can be replaced by other valid values. La %~ sintassi viene terminata da un numero di argomento valido. I %~ modificatori non possono essere usati con %*.

Remarks

  • Uso dei parametri batch:

    Batch parameters can contain any information that you can pass to a batch program, including command-line options, file names, the batch parameters %0 through %9, and variables (for example, %baud%).

  • Uso del <label> parametro :

    By using call with the <label> parameter, you create a new batch file context and pass control to the statement after the specified label. The first time the end of the batch file is encountered (that is, after jumping to the label), control returns to the statement after the call statement. La seconda volta che viene rilevata la fine del file batch, lo script batch viene chiuso.

  • Uso di pipe e simboli di reindirizzamento:

    Do not use pipes (|) or redirection symbols (< or >) with call.

  • Esecuzione di una chiamata ricorsiva

    È possibile creare un programma batch che chiama se stesso. Tuttavia, è necessario fornire una condizione di uscita. In caso contrario, i programmi batch padre e figlio possono eseguire cicli senza fine.

  • Uso delle estensioni dei comandi

    If command extensions are enabled, call accepts <label> as the target of the call. La sintassi corretta è call :<label> <arguments>.

Examples

Per eseguire il programma checknew.bat da un altro programma batch, digitare il comando seguente nel programma batch padre:

call checknew

Se il programma batch padre accetta due parametri batch e si vuole che passi tali parametri a checknew.bat, digitare il comando seguente nel programma batch padre:

call checknew %1 %2