IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
Expand all | Collapse all

CallingPerforming Command Shell functions in webMethods

  • 1.  CallingPerforming Command Shell functions in webMethods

    Posted 01/07/03 10:51 PM

    Are there built-in services to copy, remove, move files in webMethods…akin to using copy or cp, delete or rm, move or mv?

    thanks in advance.
    KrishnaN


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 2.  RE: CallingPerforming Command Shell functions in webMethods



  • 3.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/07/03 11:02 PM

    There is an example of calling a shell command in WmSamples. See commandlineExec example based around
    Process child = Runtime.getRuntime().exec(execFile);

    There are also examples that include deleteFile in the IO folder of WmSamples.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 4.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/07/03 11:07 PM

    Krishnan,

    The only I have done is using Java services. I am attaching the code for copyFile and you can write the move and delete based on that.

    Thanks
    Chris


    IDataCursor idcPipeline = pipeline.getCursor();

    String strFilename = “”;
    String strSourceDirectory = null;
    String strTargetDirectory = null;

    if (idcPipeline.first(“filename”))
    {
    strFilename = (String)idcPipeline.getValue();
    }
    else
    {
    throw new ServiceException(“Copy Failed: Filename is null!”);
    }
    if (idcPipeline.first(“sourceDirectory”))
    {
    strSourceDirectory = (String)idcPipeline.getValue();
    }
    if (idcPipeline.first(“targetDirectory”))
    {
    strTargetDirectory = (String)idcPipeline.getValue();
    }

    if (strSourceDirectory != strTargetDirectory)
    {

    FileReader frSourceFile = null;
    FileWriter fwTargetFile = null;
    File sourceFile = null;
    File targetFile = null;

    try
    {

    sourceFile = new File(strSourceDirectory, strFilename);
    targetFile = new File(strTargetDirectory, strFilename);

    if (!sourceFile.exists() || sourceFile.isDirectory())

    {

    throw new ServiceException("MOVE ERROR: Source file not found (" + sourceFile.getAbsolutePath() + ")"); 
    

    }

    frSourceFile = new FileReader(sourceFile);
    fwTargetFile = new FileWriter(targetFile);

    int c;
    while ((c = frSourceFile.read()) != -1)
    {
    fwTargetFile.write(c);
    }

    idcPipeline.insertAfter(“message”, "Copied: " + sourceFile.getAbsolutePath() + " to " + strTargetDirectory);

    }
    catch (Exception e)
    {
    throw new ServiceException(e.getMessage());
    }
    finally
    {
    try
    {
    frSourceFile.close();
    fwTargetFile.close();
    }
    catch (Exception e)
    {
    }
    sourceFile = null;
    targetFile = null;
    }
    }

    idcPipeline.destroy();


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/07/03 11:08 PM

    Krishnan,

    Here is the code for Delete…
    Basically in Java we have File object which we can use for this purpose.

    Thanks
    Chris


    String strFilename = in.getString(“filename”);

    File file;

    file = new File(strFilename);

    if (!file.exists() || file.isDirectory())

    {

    out.put(“$error”, “File Delete Error”);

    out.put(“$errorMessage”, “File Delete Error: Source file not found (” + file.getAbsolutePath() + “)”);

    return out;

    }

    try

    {

    file.delete();

    file = null;
    }

    catch (SecurityException e)

    {

    out.put(“$error”, e.toString());

    out.put(“$errorMessage”, e.getMessage());

    return out;

    }


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 6.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/07/03 11:30 PM

    Create a Batch file in case of Windows or Unix script and execute the script from a Java services


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 7.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/07/03 11:45 PM

    You can download Toolbox package from wmusers.com I have most of these services written in Java directory listing delete, copy etc.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 8.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/08/03 01:04 AM

    thanks guys…for the bunch of responses. Extremely elated!!


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 9.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/08/03 03:25 AM

    This is off-topic – I just wanted to ask who the “sonam” who made the first response is? It wasn’t me.

    Our usernames differ by a capitalization (mine: “Sonam” v/s: “sonam”). Does WMusers.com use authentication cookies? Maybe it’s time further qualify my username.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 10.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/08/03 03:31 AM

    [ Offtopic again] Er, it could have been me - the question looks familiar. Gee, I looked at it today, and I didn’t think I’d be that abrupt.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 11.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/08/03 02:34 PM

    Okay, confession time! - Pefectly off-topic too!

    That was me who used the name “sonam”. I was being bitchy and irritated when the question popped up in my inbox. It was meant to be silly, not offensive!

    Have a wonderful day guys!


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 12.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/08/03 02:36 PM

    Krishnan, One more thing. If you want the code to scan a directory and process a bunch of files at a time, let me know.

    Thx


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 13.  RE: CallingPerforming Command Shell functions in webMethods

    Posted 01/09/03 03:22 AM

    [ Off topic - last time! ]
    > That was me who used the name “sonam”. I was being
    > bitchy and irritated when the question popped up in my
    > inbox. It was meant to be silly, not offensive!

    Thanks VR. You really shouldn’t have done it, but you know that already :slight_smile:

    Since I remembered reading the question, I began to think that perhaps I had replied and the memory had been repressed (sort of “Dr. Jekyll & Mr. Hyde”) That clears it up. >

    Thanks again. .


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods