开发者

How do I close a file created from command line?

I'm writing command line output to a file and then want to open this file in notepad. So I wrote something like the following (simplified example):

set logPath=log.txt
echo %date% %time% > %logPath%
notepad %logPath%

But the problem is that when the last command is run (notepad %logPath%)开发者_运维问答, the file is not yet created (or the contents is not flushed to it), so notepad doesn't open non-existent file or opens an empty one (depends).

So I would like to know if there's a way to force file close from command line.

UPD: thank you for comments, you're right: this particular (simplified) example really does work. I tried on W7 and there are reports in comments that it does work in XP and Vista. It doesn't in the original script, will try to look for an error there.


Your example code works for me under Microsoft Windows XP [version 5.1.2600]. As far as I know you only need to close file you opened and piping is not opening.

So you should check your real code for some error (update your question with it?).


Try this:

echo %date% %time% > log.txt
notepad %logPath%

I think, it expects a filename on redirection and not a variable name.


The problem seem strange, but if its occuring, Why not wait for a sec

CHOICE /C:x /T:x,1 > NUL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜