How do you access Powershell in MATLAB interactively

26 views (last 30 days)
I am trying to leverage the "-AsSecureString" feature in Powershell to hide some confidential text strings for future use. I am struggling at the first step. The command in cmd is
powershell "$a=Read-Host -Prompt 'enter your input' -AsSecureString"
which works well from cmd.
When I call the same command with the system function in MATLAB, I get an empty interface on which I can type anything but cannot exit. There is no prompt, and my input string is visible and not secure. Getting this to work would be ideal for my problem, and I can get this to work from cmd. unfortunately, calling it from MATLAB just does not work. Is there a work around for this?

Answers (2)

Rahul
Rahul on 24 Jan 2025
I understand that you wish to run powershell commands from MATLAB and are facing the issue of getting an exmpty interface. As suggested in the following MATLAB Answers, you consider following the given workarounds:
  • Inside MATLAB -> type !powershell in the command window. This will open power shell in interactive mode. From there you can execute your powershell commands.
  • Use 'system' command in MATLAB and add the powershell command inside the 'system' function parenthesis.
Here are examples:
% Workaround 1
!powershell
% Workaround 2
system(powershell "$a=Read-Host -Prompt 'enter your input' -AsSecureString")
Refer to the following MathWorks documentation to know more:
Thanks.

Walter Roberson
Walter Roberson on 24 Jan 2025
Powershell implies that you are using Windows. In that case you can use System.Diagnostics.Process to configure input and output to a Powershell process. See the outline at https://www.mathworks.com/matlabcentral/answers/2002092-system-diagnostics-process-doesn-t-execute-all-commands-in-external-file#answer_1280947

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!