using CMD with powershell exits with 259 powershell pipe error

Forums Desktop Info using CMD with powershell exits with 259 powershell pipe error

Viewing 5 reply threads
  • Author
    Posts
    • #2233
      AvatarMatevž Ž.

      Hi there,

      I’m trying to set up DesktopInfo on my PC. I gather system information mostly with powershell scripts. Here is an example:

      [SCRIPT BEGIN]
      CMD=active:1,interval:10,file:powershell.exe,parameters:-File .\get_wibukey_detected_status.ps1,text:WibuKey license detected status:,display:(%1 %2 %3) %3[b:OK – detected.:not detected!]
      [SCRIPT END]

      The powershell script looks like this:
      [SCRIPT BEGIN]
      $result = 0
      $status = & ‘C:\Program Files (x86)\WIBUKEY\Bin\wku32.exe’
      if ($status -like ‘*1 WibuBox at 1 port found*’)
      {
      $result = 1
      }
      exit $result
      [SCRIPT END]

      What I am confused about is that I often get return code 259 (which is a powershell pipe error) for %3. Am I doing something wrong with how I use Desktop info or is this a bug?

      Kind regards

      0
    • #2234
      GlennGlenn
      Keymaster

      I’m not a Powershell guru but the only possible pipe operation I can see is the line that executes wku32.exe and pipes the output to the $status variable. Why that would generate an error is a mystery. Is it possible the command output might return an array instead of a single string?

      0
      • #2235
        AvatarMatevž Ž.

        How does DesktopInfo get %3 for CMD? Maybe I’m exiting the powershell script in the wrong way.

        0
        • #2236
          AvatarMatevž Ž.

          I also see that while executing this powershell script returns 0, desktop info still shows 1 as %3, and I am not sure where things go wrong. Do you have any ideas?

          0
      • #2244
        AvatarMatevž Ž.

        Do you have a working example of desktopinfo.ini file and a powershell script run by CMD command that would display the return code as parameter %3?

        I’m posting here my desktopinfo.ini file and a simple powershell script which always return 1 for %1, 0 for %2 and 1 for %3. So I am looking for a working example to display the correct value for %3, either for .bat or .ps1 script.

        ———————————desktopinfo.ini———————————
        [options]
        # size and position
        top=0
        right=0
        width=360

        # font
        font-face=Arial
        font-size=10

        # logging
        log=desktopinfo.log
        log-level=error

        desktopinfo64=1

        [screen-saver]
        font-face=Comic Sans MS
        font-size=16
        centerv=1
        centerh=1

        [items]
        CMD=active:1,interval:2,file:powershell.exe,directory:”C:\Program Files\DesktopInfo201″,parameters: -File test.ps1,text:test:,display: %1 %2 %3

        ———————————test.ps1———————————
        function ExitWithCode($exitcode) {
        $host.SetShouldExit($exitcode)
        exit $exitcode
        }

        ExitWithCode 4

        0
    • #2237
      GlennGlenn
      Keymaster

      The exit code is retrieved using GetExitCodeProcess.

      I don’t understand your next statement. Have you tried debugging this script in Powershell ISE?

      0
      • #2238
        AvatarMatevž Ž.

        Hi Glenn. I have tried debugging with powershell ISE. The following screenshot explains the situation:

        You can see the powershell script that is called by desktop info and continuously returns 1 for the %3 parameter. Then you see its exit code when called by powershell ISE. It returns 4. So what I expect should be the right behavior (according to the documentation – I hope I didnt overlook any detail) is that desktop info should return 4 as parameter %3.

        Do you know why desktop info shows 1 instead of 4 for the parameter %3?

        0
    • #2239
      AvatarMatevž Ž.

      screenshot
      Untitled

      0
    • #2240
      GlennGlenn
      Keymaster

      Powershell is a thing.

      I found it impossible to get it to reliably return an exit code in the expected way. I found a discussion on stackoverflow that suggests using a function which seemed to work for me:

      https://stackoverflow.com/questions/50200325/returning-an-exit-code-from-a-powershell-script

      
      
      function ExitWithCode($exitcode) {
        $host.SetShouldExit($exitcode)
        exit $exitcode
      }
      
      try
      {
      	$status = & 'dir'
      	write-host $status
      	if ($status -like '*text.ps1*')
      	{
      		write-host "detected"
      		ExitWithCode 3
      	}
      	write-host "not detected"
      	ExitWithCode 4
      }
      catch
      {
      	write-host "error"
      	ExitWithCode 5
      }
      • This reply was modified 8 months, 2 weeks ago by GlennGlenn.
      • This reply was modified 8 months, 2 weeks ago by GlennGlenn.
      0
      • #2245
        AvatarMatevž Ž.

        Do you have a working example of desktopinfo.ini file and a powershell script run by CMD command that would display the return code as parameter %3?

        I’m posting here my desktopinfo.ini file and a simple powershell script which always return 1 for %1, 0 for %2 and 1 for %3. So I am looking for a working example to display the correct value for %3, either for .bat or .ps1 script.

        ———————————desktopinfo.ini———————————
        [options]
        # size and position
        top=0
        right=0
        width=360

        # font
        font-face=Arial
        font-size=10

        # logging
        log=desktopinfo.log
        log-level=error

        desktopinfo64=1

        [screen-saver]
        font-face=Comic Sans MS
        font-size=16
        centerv=1
        centerh=1

        [items]
        CMD=active:1,interval:2,file:powershell.exe,directory:”C:\Program Files\DesktopInfo201″,parameters: -File test.ps1,text:test:,display: %1 %2 %3

        ———————————test.ps1———————————
        function ExitWithCode($exitcode) {
        $host.SetShouldExit($exitcode)
        exit $exitcode
        }

        ExitWithCode 4

        0
    • #2247
      GlennGlenn
      Keymaster

      I copied your CMD and test.ps1 code and it worked for me. I tried a batch file and that also worked as expected. As best I can tell DesktopInfo is functioning correctly. Why powershell is returning exit code 1 is a mystery.

      (check the encoding of the ps1 file?)

      try this:

      CMD=active:1,interval:3,file:powershell.exe,parameters:-command exit 4

      0
Viewing 5 reply threads
  • The topic ‘using CMD with powershell exits with 259 powershell pipe error’ is closed to new replies.
Do NOT follow this link or you will be banned from the site!