新手批处理问题 - 创建文件

时间:2016-01-13 21:31:03

标签: batch-file createfile

我正在开发一个批处理程序,可以扫描PC的各个部分,并将它们记录到一个文件中。令人惊讶的是,我无法让程序创建要写入的文件。然后我尝试创建一个文件,我相当肯定会工作;它如下:

@echo off
ipconfig > ip.txt
timeout 5

但是,这也无法写入文件ip.txt。我也尝试了以下程序,但没有成功。

@echo off
echo Test > test.txt
timeout 3

如果有人能够提供建议,我将非常感激。

不存在任何错误消息,并单击链接批处理文件

问题已解决,从Win10降级到Win7并且不再遇到问题。不是一个很好的解决方案。

1 个答案:

答案 0 :(得分:0)

ipconfig > %userprofile%\desktop\ip.txt

使用完整路径。这会将您的桌面指定为放置文件的位置。

请参阅Set /?获取帮助,然后输入set以查看标准变量。

&    seperates commands on a line.

&&    executes this command only if previous command's errorlevel is 0.

||    (not used above) executes this command only if previous command's =
errorlevel is NOT 0

>    output to a file

>>    append output to a file

<    input from a file

|    output of one command into the input of another command

^    escapes any of the above, including itself, if needed to be passed =
to a program

"    parameters with spaces must be enclosed in quotes

+ used with copy to concatinate files. E.G. copy file1+file2 newfile

, used with copy to indicate missing parameters. This updates the files =
modified date. E.G. copy /b file1,,

%variablename% a inbuilt or user set environmental variable

!variablename! a user set environmental variable expanded at execution =
time, turned with SelLocal EnableDelayedExpansion command

%<number> (%1) the nth command line parameter passed to a batch file. %0 =
is the batchfile's name.

%* (%*) the entire command line.

%<a letter> or %%<a letter> (%A or %%A) the variable in a for loop. =
Single % sign at command prompt and double % sign in a batch file.