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 called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Translate the entire conversation x

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

LS_10938759
2-Explorer

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

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!

 

6 REPLIES 6
jack15
12-Amethyst
(To:LS_10938759)

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

RPN
17-Peridot
17-Peridot
(To:jack15)

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 😉😅

jack15
12-Amethyst
(To:RPN)

I am using the bat, My program executes properly, but when it completes during/after the call to `ProEngineerEnd` the parametric.psf file is deleted.

I also always get exit code = 1 this doesn't seem like an issue, I also assume the exit code is coming from cmd.exe 

RPN
17-Peridot
17-Peridot
(To:jack15)

What is your intend, just start Creo and later do some trail files via mapkeys or something like this?

 

You will have no connection to Creo if you start this way.

 

I never tested ProEngineerEnd() without ProEngineerStart()

 

What are you doing with this timeout? Do you wait for the PID?

jack15
12-Amethyst
(To:RPN)

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

RPN
17-Peridot
17-Peridot
(To:jack15)

Okay now ProEngineerEnd makes more sense. 

Have a good time and hopefully successful 😉

Announcements

Top Tags