cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Run .bat Using Workflow

jmccormick-4
7-Bedrock

Run .bat Using Workflow

Hi Everyone,

Is there a way for me to run a batch file (.bat) stored on the Windchill server using Workflows?

I found the following PTC support document:

https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS165653&lang=en&source=snippet

But I've not been able to get it to work as of yet. Does the above article seem correct, or is there another method that can be used?

Thanks in advance for your help!

ACCEPTED SOLUTION

Accepted Solutions

Hi jmccormick-4‌,

I had done similar kind of testing long back. I am sharing steps for your reference. I hope it will help you.

  • Create two String variables at the “Process level” namely: Context and Folder with blank default value
  • Use a Expression robot to initialize these variables.
  • Suppose you are running a workflow on the WTPart (which is in this case your PBO). The expression robot will contain a code something like the one below:

  1. System.out.println("\n\n\t\t******I'm Going In*****************");

String pbo=primaryBusinessObject.toString();

  1. wt.fc.ObjectIdentifier oid =wt.fc.ObjectIdentifier.newObjectIdentifier(pbo);
  2. wt.part.WTPart part=(wt.part.WTPart) wt.fc.PersistenceHelper.manager.refresh(oid);

//get the Context

Context = part.getContainerName();

//get the Folder

Folder = part. getFolderPath();

  1. System.out.println("\n\n\t\t Context is ->"+ Context +"\n\t\t Folder is ->"+ Folder);

  • Now, define the Application Robot which will look like the one below:


launch robot.png


  • Create a sample batch file at D:\Test_Folder\Batch_file_Name.bat
  • The batch file should listen for the arguments passed using “%argumentnumber” (for example %1, %2, and so on) sign as shown below: (Passing arguments to Batch files concept)


bat file.png


Thanks,

Shirish

View solution in original post

3 REPLIES 3

Hi jmccormick-4‌,

I had done similar kind of testing long back. I am sharing steps for your reference. I hope it will help you.

  • Create two String variables at the “Process level” namely: Context and Folder with blank default value
  • Use a Expression robot to initialize these variables.
  • Suppose you are running a workflow on the WTPart (which is in this case your PBO). The expression robot will contain a code something like the one below:

  1. System.out.println("\n\n\t\t******I'm Going In*****************");

String pbo=primaryBusinessObject.toString();

  1. wt.fc.ObjectIdentifier oid =wt.fc.ObjectIdentifier.newObjectIdentifier(pbo);
  2. wt.part.WTPart part=(wt.part.WTPart) wt.fc.PersistenceHelper.manager.refresh(oid);

//get the Context

Context = part.getContainerName();

//get the Folder

Folder = part. getFolderPath();

  1. System.out.println("\n\n\t\t Context is ->"+ Context +"\n\t\t Folder is ->"+ Folder);

  • Now, define the Application Robot which will look like the one below:


launch robot.png


  • Create a sample batch file at D:\Test_Folder\Batch_file_Name.bat
  • The batch file should listen for the arguments passed using “%argumentnumber” (for example %1, %2, and so on) sign as shown below: (Passing arguments to Batch files concept)


bat file.png


Thanks,

Shirish

Hi Shirish,

That's great that's exactly what I was looking for thanks for your help!

I was wondering if you could point me in the direction of somewhere were I can learn more about these expressions within Windchill:

  1. System.out.println("\n\n\t\t******I'm Going In*****************"); 
  2.  
  3. String pbo=primaryBusinessObject.toString(); 
  4.  
  5. wt.fc.ObjectIdentifier oid =wt.fc.ObjectIdentifier.newObjectIdentifier(pbo); 
  6. wt.part.WTPart part=(wt.part.WTPart) wt.fc.PersistenceHelper.manager.refresh(oid); 
  7.  
  8. //get the Context  
  9. Context = part.getContainerName(); 
  10. //get the Folder 
  11. Folder = part. getFolde
  12.  
  13. rPath(); 
  14.  
  15.  
  16. System.out.println("\n\n\t\t Context is ->"+ Context +"\n\t\t Folder is ->"+ Folder); 

I want to use either the WT Part or EPM Document going through the robot (they will both go through this process). And I just want to extract the part number from the file, but I'm not sure what the equivalent of getContainerName would be for the part number.

Any help is greatly appreciated!

Many thanks,

Hi jmccormick-4‌,

You can learn more about Expression Robot from here:

http://support.ptc.com/cs/help/windchill_hc/wc102_hc/index.jspx?id=WFRobotsAbout&action=show

http://support.ptc.com/cs/help/windchill_hc/wc102_hc/index.jspx?id=WFExecExprRobotSampleSetAttr&action=show

To extract the part number, you can use getNumber() API call.

I hope this help you!

Regards,

Shirish

Announcements


Top Tags