Announcement

Collapse
No announcement yet.

return error from external conversion program?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • return error from external conversion program?

    Hi - fantastic app guys. I've written a utility to convert DBF (DBase) files to text and back, and I'm calling it via a rule in Beyond Compare. I'd like to know if BC2 checks for any return value when calling external conversion programs. This is because if the conversion fails for any reason, BC2 will end up writing the .TMP file it thinks contains data to the real file, which zeros the file

    I've tried calling the app directly and having the app return -1 for 'conversion failed', but BC2 always preceeds as if the conversion succeeded. I haven't tried calling a batch file to call the conversion app, and setting an errorlevel yet as I'd rather not have to do this anyway...

    Any advice would be appreciated. Thanks!

  • #2
    Re: return error from external conversion program?

    Does it overwrite/zero out the file upon a Save, or by simply opening it?

    We currently are not checking return codes for our Rule conversion, but it shouldn't save back over the file unless you select to save it (using the "Run when Saving" command line). If you remove that command line entirely, then it should not be able to overwrite your original file at all.
    Aaron P Scooter Software

    Comment


    • #3
      Re: return error from external conversion program?

      Yes it overwrites/zeroes only on save, not load. My utility converts from DBF to text and back, which makes using BC2 twice as useful (merging and saving changes). Without checking the return code from the external program, I assume there is no way to avoid this issue?

      Comment


      • #4
        Re: return error from external conversion program?

        Right. Currently, we assume that supplied .exe will 'work' when saving. I've brought the issue up with the development team here and we will investigate implementing checking error codes, or another solution, in a future version.

        One thing you may want to try: Save As... also uses the conversion application, so it should not zero out the original file if it fails. Another idea would be for your Save command to create a backup of the file first, in case it fails.
        Aaron P Scooter Software

        Comment


        • #5
          Re: return error from external conversion program?

          Thanks - this would be a useful addition. Save As does work - i.e. your original files are left alone, but this is clearly not optimal. And unfortunately the save command can't take a backup of the file because it is only passed two .TMP files from BC - it has no idea what file the .TMP file will be written back to by BC afterwards (and it doesn't make sense to 'maintain state' between program runs i.e. between load and save operations). Thanks for the info, however - for now I guess all I can do is list this as a limitation to be aware of in the conversion utility's associated readme file.

          Comment


          • #6
            Re: return error from external conversion program?

            Another option is for BC to backup the files upon save. There is an option under Tools->Options->Backups. From here, check "Backup files before save" This will create a 1 level deep backup of your file before saving it. Does this option work in your current directory structure?

            Also, do you know why the conversion fails and overwrites the original tmp file with blank information? The MSExcel Merge rule in our Additional Downloads section fails to find the temp file upon a failed save, and doesn't overwrite the original.
            http://www.scootersoftware.com/suppo..._morerules.php
            Aaron P Scooter Software

            Comment


            • #7
              Re: return error from external conversion program?

              Backup upon save is not really a desirable solution, however pointing me to the MSExcel Merge rule gave me the key to working around this issue. The reason MSExcel Merge does not overwrite your original file if a conversion fails is because it deletes the destination temporary file before it does anything:

              [xmlss2xls.vbs - line 24]
              Set oFileSys = CreateObject("Scripting.FileSystemObject")
              oFileSys.DeleteFile WScript.Arguments(1)

              So, when the tool completes and Beyond compare goes to copy the destination .TMP file to the real destination file being viewed, it fails (file does not exist) and displays and error dialog. This cancels the save and the user is forced to discard or cancel their changes. BC2 should treat an error returned from an external conversion app in the same way.

              I've implemented this workaround in my tool and it's ok now. It would still of course be better if BC2 didn't need to throw an error that a .TMP file doesn't exist to achive this functionality. In fact, I've had to add a -bc2 switch to my conversion application because normally you wouldn't want to delete the destination file if the conversion fails when the utility is called directly (i.e. not involving .TMP files). Otherwise the user would loose any data in the destination file!

              BTW, the conversion can fail if the user has edited the text such that it is not in a convertable format anymore (e.g. deleted table rows/columns that mean it can't be translated to a DBF file). This is the same for the MS Excel Merge module, which has to convert XML to XLS, if you, for example, delete something that means the XML syntax is invalid (e.g. just delete the last line).

              Comment

              Working...
              X