<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic C# Process running parametric.exe returning exit code 1 with errors in Customization</title>
    <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/961065#M13221</link>
    <description>&lt;P&gt;Hi everyone, I'm trying to run a custom Creo parametric C++ plugin by creating a Process in C# and calling "parametric.exe".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using Creo Parametric 7.0.9.0 with C# .NET Framework 4.8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the C# code to create the process and run parametric.exe:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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) =&amp;gt;
{
    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) =&amp;gt; errorData.Append(args.Data ?? string.Empty);

_ = process.Start();

process.BeginErrorReadLine();

bool exited = process.WaitForExit(_settings.CreoParametricTimeoutMs);

Logger.LogMessage(errorData.ToString());&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, every time the process exits, it returns a Process.ExitCode of 1 and the errorData has the following errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Files\PTC\Creo was unexpected at this time.
The process cannot access the file because it is being used by another process.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with this issue would be greatly appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jul 2024 16:15:42 GMT</pubDate>
    <dc:creator>LS_10938759</dc:creator>
    <dc:date>2024-07-12T16:15:42Z</dc:date>
    <item>
      <title>C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/961065#M13221</link>
      <description>&lt;P&gt;Hi everyone, I'm trying to run a custom Creo parametric C++ plugin by creating a Process in C# and calling "parametric.exe".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using Creo Parametric 7.0.9.0 with C# .NET Framework 4.8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the C# code to create the process and run parametric.exe:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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) =&amp;gt;
{
    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) =&amp;gt; errorData.Append(args.Data ?? string.Empty);

_ = process.Start();

process.BeginErrorReadLine();

bool exited = process.WaitForExit(_settings.CreoParametricTimeoutMs);

Logger.LogMessage(errorData.ToString());&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, every time the process exits, it returns a Process.ExitCode of 1 and the errorData has the following errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Files\PTC\Creo was unexpected at this time.
The process cannot access the file because it is being used by another process.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with this issue would be greatly appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 16:15:42 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/961065#M13221</guid>
      <dc:creator>LS_10938759</dc:creator>
      <dc:date>2024-07-12T16:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019635#M14180</link>
      <description>&lt;P&gt;Any update on this? I found this when searching for an issue I was experiencing&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 21:05:32 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019635#M14180</guid>
      <dc:creator>jack15</dc:creator>
      <dc:date>2025-06-09T21:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019639#M14181</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For example the license info🥸&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Next asynchronous mode requires the env vars to have access to pro comm messages.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;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.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I would try first to start an asynchronous session before making the next step.&amp;nbsp;&lt;BR /&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just my 2 Cents &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 21:50:24 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019639#M14181</guid>
      <dc:creator>RPN</dc:creator>
      <dc:date>2025-06-09T21:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019750#M14182</link>
      <description>&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;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&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 13:16:15 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019750#M14182</guid>
      <dc:creator>jack15</dc:creator>
      <dc:date>2025-06-10T13:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019953#M14185</link>
      <description>&lt;P&gt;What is your intend, just start Creo and later do some trail files via mapkeys or something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have no connection to Creo if you start this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I never tested&amp;nbsp;ProEngineerEnd() without&amp;nbsp;ProEngineerStart()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you doing with this timeout? Do you wait for the PID?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 10:54:06 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1019953#M14185</guid>
      <dc:creator>RPN</dc:creator>
      <dc:date>2025-06-11T10:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1020018#M14188</link>
      <description>&lt;P&gt;I have figured out the issue I was encountering at least. The length of arguments I was passing in were too long.&lt;BR /&gt;&lt;BR /&gt;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)&lt;BR /&gt;&lt;BR /&gt;Then my synchronous application runs and calls ProEngineerEnd() when complete&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 14:28:49 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1020018#M14188</guid>
      <dc:creator>jack15</dc:creator>
      <dc:date>2025-06-11T14:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: C# Process running parametric.exe returning exit code 1 with errors</title>
      <link>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1020106#M14191</link>
      <description>&lt;P&gt;Okay now&amp;nbsp;&lt;SPAN&gt;ProEngineerEnd makes more sense.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Have a good time and hopefully successful &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 20:43:31 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Customization/C-Process-running-parametric-exe-returning-exit-code-1-with/m-p/1020106#M14191</guid>
      <dc:creator>RPN</dc:creator>
      <dc:date>2025-06-11T20:43:31Z</dc:date>
    </item>
  </channel>
</rss>

