为什么这些DOS变量为空? (例如,%DATE%,%ERRORLEVEL%) [英] Why are these DOS Variables Empty? (e.g. %DATE%, %ERRORLEVEL%)

查看:93
本文介绍了为什么这些DOS变量为空? (例如,%DATE%,%ERRORLEVEL%)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows XP SP3。

I am using Windows XP SP3.

如果我打开命令提示符窗口,然后键入

If I open a Command Prompt window, and type

ECHO %DATE%

我得到:

14-08-2018



like I should.

但是如果我退出Windows并从具有DOS的可启动USB闪存驱动器启动计算机,则为

(实际DOS ,而不是Windows中的命令提示符),

并输入相同的命令,

然后%DATE%似乎为空

But If I exit Windows and boot my computer from a bootable USB Flash Drive that has DOS
(real DOS, not the command prompt inside Windows),
and enter the same command,
then %DATE% seems to be empty.

命令

ECHO %DATE%

回复

ECHO is On

因为它认为我刚刚写了 ECHO

,因为从%DATE%返回的值是。

Because it thinks that I just wrote ECHO,
since the value returned from %DATE% is "".

我尝试了2种不同的DOS版本。.

Win98的DOS和WinME的DOS。

(2个不同的USB闪存驱动器)

I tried it with 2 different DOS Versions..
Win98's DOS, and WinME's DOS.
(2 different USB Flash Drives)

有人知道我为什么吗无法在实际的DOS中获取日期,

,但是当我在Windows的命令提示符下可以成功获取日期时?

Does anyone know why I cannot get the Date in real DOS,
while I can successfully get it when I am in Windows' command prompt?

推荐答案

%ERRORLEVEL%在DOS中不是变量


%ERRORLEVEL%


在DR-DOS 7.02及更高版本的COMMAND.COM中,此伪变量返回外部程序或程序返回的最后一个错误级别。 RETURN 命令,fe 0 .. 255。另请参见Windows下同名的伪变量%ERRORLEVEL% IF ERRORLEVEL 条件命令。

%ERRORLEVEL%

In COMMAND.COM of DR-DOS 7.02 and higher, this pseudo-variable returns the last error level returned by an external program or the RETURN command, f.e. "0".."255". See also the identically named pseudo-variable %ERRORLEVEL% under Windows and the IF ERRORLEVEL conditional command.

https://en.wikipedia.org/wiki/Environment_variable#DOS

如您所见,它仅存在于DR-DOS 7.02及更高版本中。 DR-DOS还只有%ERRORLVL%

As you can see, it only exists in DR-DOS 7.02 onwards and Windows. DR-DOS also has %ERRORLVL%

OTOH %DATE% Windows上存在

OTOH %DATE% only exists on Windows


%DATE%


此伪-variable扩展到当前日期。日期将根据当前用户的日期格式首选项显示。

%DATE%

This pseudo-variable expands to the current date. The date is displayed according to the current user's date format preferences.

https://en.wikipedia.org/wiki/Environment_variable#Windows

它们是cmd.exe的新功能需要启用命令扩展

They're new features of cmd.exe which requires command extension to be enabled


如果禁用了命令扩展,将无法访问以下动态变量:

If Command Extensions are disabled, the following dynamic variables will be not accessible:

%CD% %DATE% %TIME% %RANDOM% %ERRORLEVEL% %CMDEXTVERSION% %CMDCMDLINE% %HIGHESTNUMANODENUMBER%

https://ss64.com/nt/syntax-variables.html

因此,如果您关闭命令扩展以实现DOS兼容性,那么您在Windows cmd.exe上也会丢失这些变量。

Therefore if you turn off command extension for DOS compatibility you'll also lose those variables on Windows cmd.exe

这篇关于为什么这些DOS变量为空? (例如,%DATE%,%ERRORLEVEL%)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆