writing a string from a batch file to a text file

Hello,
I would like ti ask this:

I have created a batch file which copies a file from a location to another..so far ok.
all i want is when the batch file fails (for some reason) to copy,then i want to write in a text file something,eg "copy failed".
I have tried the TYPE command with redirection (TYPE fff > test.txt) and i got an error like this "file not found".

Does anyone knows how can i do this?

Thank you in advanced.

Jim - Greece


Comments

  • TYPE prints the content of a file, use ECHO

    [code]
    copy %1 %2
    if errorlevel 0 goto OK
    echo COPY FAILED > error.log

    :OK
    [/code]
  • : TYPE prints the content of a file, use ECHO
    :
    : [code]
    : copy %1 %2
    : if errorlevel 0 goto OK
    : echo COPY FAILED > error.log
    :
    : :OK
    : [/code]
    :

    ok thank you,
    do u know which parameter i must use in order to run an msdos window always minimized?
  • : : TYPE prints the content of a file, use ECHO
    : :
    : : [code]
    : : copy %1 %2
    : : if errorlevel 0 goto OK
    : : echo COPY FAILED > error.log
    : :
    : : :OK
    : : [/code]
    : :
    :
    : ok thank you,
    : do u know which parameter i must use in order to run an msdos window always minimized?
    :

    In VisualBasic, the Shell command has an extra argumnet where you can set the state of the program you open (same for Win32 api)
  • If your using visual basic

    put in your code where you copying the batchfile:

    On Error goto ErrorHandler
    (Errorhandler can be called anything you want)<-this is a comment

    Then in the same procedure type

    ErrorHandler: (or whatever you named it)
    (whatever you want to do)
    eg...MsgBox "Unexpected error" & _
    Str$(Err.Number) & _
    " in subroutine DoSomething." & _
    vbCrLf & _
    Err.Description


    this above code will give you the same error message that appears when somthing goes wron with your operating system!

    Rather than msgbox just addd the code to create a log file if you like!




    A Visual Basic program uses the On Error statement to register error handling code. This statement can take one of three forms:
    On Error GoTo 0
    On Error Resume Next
    On Error GoTo line







Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories