views:

47

answers:

3

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.

A: 

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?).

RC
@RC How are piping and opening different?
Midhat
Piping is handled by the shell and opening is handled by the developper
RC
A: 

Try this:

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

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

anilmwr
I tried that, didn't work for me, unfortunately.Actually, I introduced a variable later, originally it was exactly how you stated.
Nikita G.
A: 

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

CHOICE /C:x /T:x,1 > NUL
Midhat
I don't think waiting is a good solution to such problem.
Nikita G.