What does /p mean in set /p?
Asked Answered
D

2

53

What does /p stand for in set /p=? I know that / enables a switch, and I'm fairly sure that I know /a is for arithmetic. I've heard numerous rumours, some saying /p is for prompt, others stating it stands for print. The only reason I slightly doubt it is prompt is because in many cases it does not ask for a prompt, yet prints on the screen, such as

<nul set /p=This will not generate a new line

But what I want to know is: Do we really know what it stands for?

Ditmore answered 5/1, 2015 at 5:18 Comment(1)
Type Help in the command prompt. For each command listed type help <command> (eg help dir) or <command> /? (eg dir /?). Using Redirection is merely automating a command, any command that reads from StdIn. See #31821069 for punctuation.Ancalin
O
36

For future reference, you can get help for any command by using the /? switch, which should explain what switches do what.

According to the set /? screen, the format for set /p is SET /P variable=[promptString] which would indicate that the p in /p is "prompt." It just prints in your example because <nul passes in a nul character which immediately ends the prompt so it just acts like it's printing. It's still technically prompting for input, it's just immediately receiving it.


NOTE: The answers below this point are for a previous version of the question.

/L in for /L generates a List of numbers.

From ping /?:

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name

Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet (IPv4-only).
    -i TTL         Time To Live.
    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated
                   and has no effect on the type of service field in the IP Header).
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host-list   Loose source route along host-list (IPv4-only).
    -k host-list   Strict source route along host-list (IPv4-only).
    -w timeout     Timeout in milliseconds to wait for each reply.
    -R             Use routing header to test reverse route also (IPv6-only).
    -S srcaddr     Source address to use.
    -4             Force using IPv4.
    -6             Force using IPv6.
Ordway answered 5/1, 2015 at 5:27 Comment(1)
I already knew what they did, and I already knew of the [command] /? syntax, but I never thought to use it because, as stated, I already knew what they did. But now that a see it, the way it is explained in the /? menus is a lot more down-to-earth as to why the abbreviation is what it is - I always used things like ss64.com and the like. Accepted, good answer.Ditmore
G
63

The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.

Two ways I've used it... first:

SET /P variable=

When batch file reaches this point (when left blank) it will halt and wait for user input. Input then becomes variable.

And second:

SET /P variable=<%temp%\filename.txt

Will set variable to contents (the first line) of the txt file. This method won't work unless the /P is included. Both tested on Windows 8.1 Pro, but it's the same on 7 and 10.

Gen answered 20/10, 2016 at 19:47 Comment(3)
Thanks for this additional answer. It was easier for me to understand. I just came here from google looking for a simple explanation, and I know sometimes if there's already an accepted answer, people won't post another.Neuropathy
This should be the marked answer. Other people responding, like pulling teeth for a simple answer. It shouldn't be like that.Lonlona
To clarify, does /P set the value of a CMD variable or an Environment Variable?Stays
O
36

For future reference, you can get help for any command by using the /? switch, which should explain what switches do what.

According to the set /? screen, the format for set /p is SET /P variable=[promptString] which would indicate that the p in /p is "prompt." It just prints in your example because <nul passes in a nul character which immediately ends the prompt so it just acts like it's printing. It's still technically prompting for input, it's just immediately receiving it.


NOTE: The answers below this point are for a previous version of the question.

/L in for /L generates a List of numbers.

From ping /?:

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name

Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet (IPv4-only).
    -i TTL         Time To Live.
    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated
                   and has no effect on the type of service field in the IP Header).
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host-list   Loose source route along host-list (IPv4-only).
    -k host-list   Strict source route along host-list (IPv4-only).
    -w timeout     Timeout in milliseconds to wait for each reply.
    -R             Use routing header to test reverse route also (IPv6-only).
    -S srcaddr     Source address to use.
    -4             Force using IPv4.
    -6             Force using IPv6.
Ordway answered 5/1, 2015 at 5:27 Comment(1)
I already knew what they did, and I already knew of the [command] /? syntax, but I never thought to use it because, as stated, I already knew what they did. But now that a see it, the way it is explained in the /? menus is a lot more down-to-earth as to why the abbreviation is what it is - I always used things like ss64.com and the like. Accepted, good answer.Ditmore

© 2022 - 2024 — McMap. All rights reserved.