Skip to main content
1-Visitor
July 12, 2024
Question

C# Process running parametric.exe returning exit code 1 with errors

  • July 12, 2024
  • 1 reply
  • 2309 views

Hi everyone, I'm trying to run a custom Creo parametric C++ plugin by creating a Process in C# and calling "parametric.exe".

 

I'm using Creo Parametric 7.0.9.0 with C# .NET Framework 4.8.

 

This is the C# code to create the process and run parametric.exe:

 

process.StartInfo.FileName = "\"C:\Program Files\PTC\Creo 7.0.9.0\Parametric\bin\parametric.exe\"";
process.StartInfo.Arguments = $"+Assypath=\"{_settings.WorkingDirectory}\\{assemblyName}\" ";
process.StartInfo.Arguments += $"+Output_Dir=\"{_settings.WorkingDirectory}\" ";
...
// Some other arg setting...
...
process.StartInfo.UseShellExecute = false;
process.EnableRaisingEvents = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;

process.Exited += (sender, args) =>
{
 int exitCode = process.ExitCode;

 if (exitCode == 0)
 {
 Logger.LogMessage("Ran successfully");
 }
 else
 {
 Logger.LogMessage($"Exited with error code: {exitCode}");
 }
};

var errorData = new StringBuilder();

process.ErrorDataReceived += (sender, args) => errorData.Append(args.Data ?? string.Empty);

_ = process.Start();

process.BeginErrorReadLine();

bool exited = process.WaitForExit(_settings.CreoParametricTimeoutMs);

Logger.LogMessage(errorData.ToString());

 

 

However, every time the process exits, it returns a Process.ExitCode of 1 and the errorData has the following errors:

 

Files\PTC\Creo was unexpected at this time.
The process cannot access the file because it is being used by another process.

 

 

The plugin calls ProEngineerEnd() to close the Creo session, but even if I remove that call from the plugin and close the Creo window manually, the same error is returned.

 

I think that the spaces in the parametric.exe path (C:\Program Files\PTC\Creo 7.0.9.0\Parametric\bin\parametric.exe) are causing the issue in the first error since it matches the "Files\PTC\Creo" section, but I'm not sure who or what is accessing that path value incorrectly. The plugin runs correctly and throws no errors of its own.

 

I'm not sure how to debug the second line as I'm not sure what file is causing the access error (unless it's talking about the "Files\PTC\Creo" path?)

 

Are these common errors that can be ignored since the Creo plugin runs successfully all thing considered? Should I just ignore the exit code 1?

 

Any help with this issue would be greatly appreciated. Thanks!

 

1 reply

12-Amethyst
June 9, 2025

Any update on this? I found this when searching for an issue I was experiencing

18-Opal
June 9, 2025

First of all I don’t understand why the executable is started instead of the bat. Because in that case you have to configure all env vars which are required by your own.

For example the license info🥸


Next asynchronous mode requires the env vars to have access to pro comm messages. 

Check the docs which’s args are supported and how you open a file as an argument. Take care with spaces and quote the path. 

I would try first to start an asynchronous session before making the next step. 

Just my 2 Cents 😉😅

12-Amethyst
June 11, 2025

I have figured out the issue I was encountering at least. The length of arguments I was passing in were too long.

To answer your question as to what I am doing, I am launching Creo with from the command line with additional arguments that get passed to my application. (Described in section "user_initialize() Arguments" of protoolkit doc)

Then my synchronous application runs and calls ProEngineerEnd() when complete