Skip to main content
Solved

why SystemCaller does not give correct exit code?

  • December 13, 2017
  • 8 replies
  • 118 views

aguan
Supporter
Forum|alt.badge.img+11
  • Supporter
  • 140 replies

I have a SystemCaller that simply deletes a file. I would assume if the deletion is successful, it would give code 0, otherwise 1. However, it always gives 0 whether the deletion is successful or not (for example, I keep the file open before hand to cause the deletion to fail). Any workaround? I could use PythonCaller to do the deletion and generate an exit code, but would be nice just do this simple operation in the SystemCaller.

Best answer by helmoet

Try PythonCaller using the follwing script:

import fme
import fmeobjects
import os

def killFile(feature):
    try:
        os.remove("e:\\data\\temp\\test.txt")
        stat = 0
    except WindowsError:
        stat = 1
    
    feature.setAttribute ('stat', stat)
    pass

When called, after execution the feature would contain an attribute stat having value of 0 (succeed) or 1 (failed) depending if the delete operation deleted the file.

0684Q00000ArL57QAF.png

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

david_r
Celebrity
  • 8394 replies
  • December 13, 2017

Which command are you using in the SystemCaller? If you're using "del", that command always return 0, which is what the SystemCaller will return as well.

See the documentation: https://ss64.com/nt/del.html

Errorlevels: DEL will return an Errorlevel of 0, irrespective if the delete succeeds or fails for any reason.


helmoet
Forum|alt.badge.img+8
  • 195 replies
  • Best Answer
  • December 13, 2017

Try PythonCaller using the follwing script:

import fme
import fmeobjects
import os

def killFile(feature):
    try:
        os.remove("e:\\data\\temp\\test.txt")
        stat = 0
    except WindowsError:
        stat = 1
    
    feature.setAttribute ('stat', stat)
    pass

When called, after execution the feature would contain an attribute stat having value of 0 (succeed) or 1 (failed) depending if the delete operation deleted the file.

0684Q00000ArL57QAF.png


aguan
Supporter
Forum|alt.badge.img+11
  • Author
  • Supporter
  • 140 replies
  • December 13, 2017

Which command are you using in the SystemCaller? If you're using "del", that command always return 0, which is what the SystemCaller will return as well.

See the documentation: https://ss64.com/nt/del.html

Errorlevels: DEL will return an Errorlevel of 0, irrespective if the delete succeeds or fails for any reason.

I see. Yes I use del command. Will change to use PythonCaller then.

 

 


aguan
Supporter
Forum|alt.badge.img+11
  • Author
  • Supporter
  • 140 replies
  • December 13, 2017

Try PythonCaller using the follwing script:

import fme
import fmeobjects
import os

def killFile(feature):
    try:
        os.remove("e:\\data\\temp\\test.txt")
        stat = 0
    except WindowsError:
        stat = 1
    
    feature.setAttribute ('stat', stat)
    pass

When called, after execution the feature would contain an attribute stat having value of 0 (succeed) or 1 (failed) depending if the delete operation deleted the file.

0684Q00000ArL57QAF.png

@helmoet. Thanks for the handy code. That is what I need when the systemCaller does not return failure code for "del file" command.

 


redgeographics
Celebrity
Forum|alt.badge.img+60
  • Celebrity
  • 3703 replies
  • March 28, 2018

Which command are you using in the SystemCaller? If you're using "del", that command always return 0, which is what the SystemCaller will return as well.

See the documentation: https://ss64.com/nt/del.html

Errorlevels: DEL will return an Errorlevel of 0, irrespective if the delete succeeds or fails for any reason.

Funny... my SystemCaller with a del command always returns 1... and always seems to fail deleting the file.

 

 


david_r
Celebrity
  • 8394 replies
  • March 28, 2018
Funny... my SystemCaller with a del command always returns 1... and always seems to fail deleting the file.

 

 

The del command may set errorlevel to 1 if you have specified an invalid switch, e.g. "/X". That's the only scenario (that I know of) where del will set the errorlevel to anything else than 0.

redgeographics
Celebrity
Forum|alt.badge.img+60
  • Celebrity
  • 3703 replies
  • March 28, 2018
The del command may set errorlevel to 1 if you have specified an invalid switch, e.g. "/X". That's the only scenario (that I know of) where del will set the errorlevel to anything else than 0.
I'm not going to bother with it to be honest, it turns out @helmoet's Python script does the trick just fine and is a much more elegant solution that what I was cobbling together (SystemCaller / FileExistenceChecker)

 


david_r
Celebrity
  • 8394 replies
  • March 28, 2018
I'm not going to bother with it to be honest, it turns out @helmoet's Python script does the trick just fine and is a much more elegant solution that what I was cobbling together (SystemCaller / FileExistenceChecker)

 

I agree :-)