1.

Solve : output to file problem?

Answer»

Hello,

I've got a BATCH file that I use to help me with my day to day activities. I've come into a problem where I call a program and pipe the information to a file, but the information always comes out empty.

I've posted the section of the batch file that's giving me trouble. It works. It will create the file, but no output goes to the file. I've tried with >> and >, but neither seem to work. I'm at a loss, really. This really isn't my line of work, but something to help me day to day. Any help would be greatly appreciated. I believe the trouble line is in teal....

:DEFAULT_PWDS
M:
CD %CHECKPWD_DIR%
set /p PWD=Enter Password for %SLID%:
IF EXIST %CHECKPWD_DIR%\check_%ORACLE_SID%.log DEL %CHECKPWD_DIR%\check_%ORACLE_SID%.log
start /WAIT /D%CHECKPWD_DIR% checkpwd %SLID%/%PWD%@%ORACLE_SID% default_passwords.txt >> %CHECKPWD_DIR%\check_%ORACLE_SID%.log

start notepad %CHECKPWD_DIR%\check_%ORACLE_SID%.log

Thank you,

JeremyA pipe "|" is used to send input to another program. If you send the information to a file, then a redirect (>) must be used


If you have used pipes, “|” with Unix Shell Programming or other environments, then a pipe with CMD (Batch) will not always work the same as other environments.

IF EXIST %CHECKPWD_DIR%\check_%ORACLE_SID%.log DEL

( in reference to the above line: You might CD to the directory where the log is and delete the log. ) ( If the log is not there, you will get a harmless message. )( a redirect will create the log automatically )

As a test use the real path and not the output of variables.

start notepad %CHECKPWD_DIR%\check_%ORACLE_SID%.log

I see no reason for start

cd to where the log is.

notepad oracle.log

We can open notepad with a batch file but the edit functions are manual.

Unix has sed which will run automatically

Good Luck



I appreciate the response, but I'm not worried about unix commands at this point.

This works just fine when I run the steps manually. It's when I put it into a larger batch file to help me with everything, no output goes to the file. The file gets created (if it does not exist), but it's always a 0kb file.

I tried your trick (taking out all the variable), but no dice. It still does the same thing. Creates an empty file. BTW, I developed with no variables and put them in after the fact.

Any other suggestions?HA! Figured it out. For some reason it doesn't redirect when the START command is used. I took out

start /I /SEPARATE /WAIT /D %CHECKPWD_DIR%

from the start and now it works like a charm....

SWEEEEEET! I guess this can be considered closed. Good to hear you solved the problem.

I'm not sure why start can cause problems.

Start opens a new window and new copy of CMD. Perhaps the file was there but HIDDEN?Quote

Start opens a new window and new copy of CMD. Perhaps the file was there but hidden?

A new copy of CMD is a bad idea in Batch programming.
Unless that is want you really want.
I'm fairly new to batch programming so the advice is noted and appreciated.


Discussion

No Comment Found