Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Documentation Question to %@PSHELL

Sep
134
1
I've played with the PSHELL-command and after a little try and error I think I can use with the
alternating double- and single quotes. My "reference command" for Powershell ist
PS:>"List Volume"|DISKPART
In PSHELL:
PSHELL /S "'List Volume'|DISKPART"

But this will not work with %@PSHELL
Echo %@PSHELL["'List Volume'|DISKPART"]
I get an error message from Powershell, Parameter could not be handled.

How is the handling with %@PSHELL ?

The manual is pretty monosyllabic there:
@PSHELL[expression] : Executes the specified PowerShell expression.

How about some example here ?
 
Here is how I see what is happening;
Code:
c:\users\jlc\utils>pshell /s "$x = 'List Volume' | DISKPART"

c:\users\jlc\utils>pshell /s "$x"

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: OPTIPLEX9010

DISKPART>
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D                       DVD-ROM         0 B  No Media
  Volume 1         SYSTEM       NTFS   Partition    300 MB  Healthy    System
  Volume 2     C   WINDOWS      NTFS   Partition    903 GB  Healthy    Boot
  Volume 3         RECOVERY     NTFS   Partition     27 GB  Healthy    Hidden
  Volume 4     G   New Volume   NTFS   Partition    465 GB  Healthy
  Volume 5     E                NTFS   Removable     29 GB  Healthy
  Volume 6     X                NTFS   Partition    232 GB  Healthy

DISKPART>

Look at the following;
Code:
c:\users\jlc\utils>echo %@execstr[pshell /s "$x"]
ECHO is OFF

Why did it return ECHO is OFF? Well, the first line of the returned results is blank.

I have found that @PSHELL is best at returning a single item, not alot of items all at once.

For me, if I want a single line from the results, determine which line I want using Powershell, save that line into a Powershell variable, and then use @PSHELL to retrieve that Powershell variable.

Joe
 
I have found that @PSHELL is best at returning a single item, not alot of items all at once.

For me, if I want a single line from the results, determine which line I want using Powershell, save that line into a Powershell variable, and then use @PSHELL to retrieve that Powershell variable.

Joe
Thank You, Joe, You made it clear for me. Before I had not realized, that %@PSHELL is a function call which can return only a single value, a number or a string, for example:
Code:
Set arSize=%@PSHELL[$x.Length]
IFF %@ISDIGIT[%arsize] THEN
  IFF %arsize GT 0 THEN
    SetArray arPS[%arsize]
    IFF %@EXECARRAY[arPS,PSHELL /S "$x"] EQ 0 THEN
      On Error Rem
      Do z=0 TO %@DEC[%_EXECARRAY]
       Echo %z, %@TRIM[%arPS[%z]]
    ENDIFF
  ENDIFF
ENDIFF
 
Last edited:
I'm not sure why you want to use @PSHELL at all for this command. DiskPart is an external executable.
This works to return the volume list using just TCC commands.
Code:
echo List Volume | diskpart
 
Works not here, Scott,
If I send this command, it has the same effect as in CMD: DISKPART prints out
it's help screen fore many times.
The reason is, that I've switch to Unicode output with TCC some time ago, but
DISKPART cannot handle commands in Unicdoe
To interact with DISKPART so I must always use a sequence like this
Code:
OPTION //UNICODEOUTPUT=No
  Echo List Volume | DISKPART
OPTION //UNICODEOUTPUT=YES
then it will work :smile:
Thanks for this hint.
 
Last edited:

Similar threads

Back
Top