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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How do I write a Batch file that will run in the Windchill Shell Environment?

GaryMansell
6-Contributor

How do I write a Batch file that will run in the Windchill Shell Environment?

I want to automate a series of Windchills task that I would normally carry out interactively using the Windchill Shell.


The Windchill Shell command shortcut appears to be:


C:\ptc\Windchill\bin\windchill.exe -w "C:\ptc\Windchill" --java="C:\ptc\Java\jre\bin\java.exe" shell


But if I put this as the first line in the Windows Batch file, it spawns a sub-shell with the Windchill Environment and hence any later commands in the batch file do not run in it.


It seems as if I need to specify a further argument to the Windchill.exe command line to refer to the commands that I want to run but this does not seem to be possible.


Can anyone advise me how to achieve this?


Thanks in advance


Gary

7 REPLIES 7

Just found the search tool - nothing to see here...


Here is the answer:


A little off topic for this thread. But in Windows you just need to create
a bat file that starts with a line like;
call c:\ptc\windchill\bin\toolssetup.bat

OK - the toolssetup.bat file does not exist in Windchill 9.1


My question still stands...

Hi Gary,


I guess, using ANT scripts would be a better choice.



In Reply to Gary Mansell:



OK - the toolssetup.bat file does not exist in Windchill 9.1


My question still stands...


Praseeth,


Thanks for taking the time to respond, but writing an ant script seems like massive over kill when all I want to do is run some command line in a Windchill Shell environment - surely there must be a way to seed the Windchill Environment into a command tool shell?


Can anyone shed any light on this?


Rgds


Gary

Gary,


Here are some examples to get you started.


This one issues a stop command to the servers and shuts them down:
D:\ptc\Windchill\bin\windchill.exe -w "D:\ptc\Windchill" --java="D:\ptc\Java\jre\bin\java.exe" stop


This one issues a start command:
D:\ptc\Windchill\bin\windchill.exe -w "D:\ptc\Windchill" --java="D:\ptc\Java\jre\bin\java.exe" start


This one gets you a Windchill shell/command prompt:
D:\ptc\Windchill\bin\windchill.exe -w "D:\ptc\Windchill" --java="D:\ptc\Java\jre\bin\java.exe" shell


This one issues a load from file command:
D:\ptc\Windchill\bin\windchill.exe wt.load.LoadFromFile


Note that you can also add some switches to actually process the file, E.G:
D:\ptc\Windchill\bin\windchill.exe wt.load.LoadFromFile -u username -p password -m D:\ptc\Windchill\loadfiles\csvmapfile_mod.txt


Hope that helps,
-----
Lewis




In Reply to Gary Mansell:



I want to automate a series of Windchills task that I would normally carry out interactively using the Windchill Shell.


The Windchill Shell command shortcut appears to be:


C:\ptc\Windchill\bin\windchill.exe -w "C:\ptc\Windchill" --java="C:\ptc\Java\jre\bin\java.exe" shell


But if I put this as the first line in the Windows Batch file, it spawns a sub-shell with the Windchill Environment and hence any later commands in the batch file do not run in it.


It seems as if I need to specify a further argument to the Windchill.exe command line to refer to the commands that I want to run but this does not seem to be possible.


Can anyone advise me how to achieve this?


Thanks in advance


Gary





Gary,


There are some options depending on what you are trying to accomplish. I use all these approaches when they fit the situation.



  • You can run batch scripts from an existing Windchill shell. That is the easiest approach but requires human interaction to kick off the process. I do this more often when I'm implementing Windchill.

  • Lewis' list of commands are perfect for common Windchill functions like start/stop and can be fully automated/scheduled. However, these are single line commands and as you noted originally, we lose the ability to programmatically work within the Windchill shell after launching it (&$^!@). This should really be enhanced by PTC to support batch creation and usage of a Windchill shell.

  • ANT works well and can be scheduled. I use it for nightly backup procedures. But it is overkill for the more simple operations and tends to run slower than batch files.

  • The last option in my arsenal is to recreate the Windchill shell environment without running the 'Windchill shell' command. This gives me a command prompt (Windchill shell) that I can interact with programatically. It also opens up the door to using PowerShell where you can really report and manipulate the Windows environment.

You have to understand what the Windchill Shell command does and how it does it for the particular Windchill release(s) you use. Launch a Windchill shell from the command line in verbose mode. For example, from a Windows command shell:



windchill.exe -v shell



Note: Replace %WT_HOME% with the actual path to your Windchill home.


The previous command generates a long list of information and you have to figure out what it is really doing (e.g. setting WT_HOME, loading properties files, configuring the ANT environment, etc). In 9.1 I found it was really setting the current directory, some key environment variables like WT_HOME and JAVA_HOME and calling setvars.bat and tools.bat. So I added this to my batch files:



set JAVA_HOME=D:\ptc\Windchill_Apps\Java


pushd %WT_HOME%\bin\


call tools.bat


Matt,


You are a star - thanks very much, I do indeed want to schedule this batch file of Windchill Shell commands to run overnight.


I am running Windchill 9.1 and have tried doing exactly what you have detailed and have proved it works.


I can now schedule some out of hours work to be done whilst I am not in the office, thus saving me having to work out of hours !!


Many thanks


Gary

Top Tags