Calling Powershell from MATLAB: AWS Example
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Running 2014A and Windows Server 2012 R2. I wish to call Powershell from inside matlab. Below is my attempt,
%%Get The required Data
[~, instance_ID] = system('powershell 2*10; echo "GET-EC2-Instance"');
[~, region_id] = system('powershell 2*10; echo "GET-AWSRegion"');
Terminate_param = true; % stop or terminate?
if(Terminate_param)
%terminate the instance
[status,cmdout] = system(['powershell 2*10; echo "Stop-EC2Instance -Instance' instance_ID ' -Region' region_id '-Terminate' '-Force"']);
else
%stop the instance
[status,cmdout] = system(['powershell 2*10; echo "Stop-EC2Instance -Instance' instance_ID ' -Region' region_id '-Force"']);
end
As you can see what I am unclear on is how to differentiate between Powershell and AWS Powershell. When I run the above commands I get the below (which is not the response I want),
[~, instance_ID] = system('powershell 2*10; echo "GET-EC2-Instance"')
instance_ID =
20
GET-EC2-Instance
When I open the executable "Windows Powershell for AWS" (as per AWS Powershell) and type the command lines, i get the below (Note I have already entered my access key, secret key and region).
PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Get-AWSRegion
Region Name IsShellDefault
------ ---- --------------
us-east-1 US East (Virginia) True
us-west-1 US West (N. California) False
us-west-2 US West (Oregon) False
eu-west-1 EU West (Ireland) False
ap-northeast-1 Asia Pacific (Tokyo) False
ap-southeast-1 Asia Pacific (Singapore) False
ap-southeast-2 Asia Pacific (Sydney) False
sa-east-1 South America (Sao Paulo) False
PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> GET-EC2Instance
GroupNames : {}
Groups : {}
Instances : {my_key_name, my_key_name, my_key_name, my_key_name...}
OwnerId : aws_account_id
RequesterId :
ReservationId : r-be212395
GroupNames : {}
Groups : {}
Instances : {my_key_name}
OwnerId : aws_account_id
RequesterId :
ReservationId : r-bbeac492
GroupNames : {}
Groups : {}
Instances : {my_key_name}
OwnerId : aws_account_id
RequesterId :
ReservationId : r-15efd42f
GroupNames : {}
Groups : {}
Instances : {my_key_name}
OwnerId : aws_account_id
RequesterId :
ReservationId : r-dc3133f2
However, none of these correspond to the instance_id of the machine from which I am making this call.
Then I run the below, getting the instance_id from the AWS management console window,
PS C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell> Stop-EC2Instance -Instance i-2810d7c6
This then stops the instance as it's supposed to.
Hence I am happy the commands work. I would just like to be able to execute these from inside MATLAB.
Also keen to hear from anyone who was experience with the AWS command line interface (CLI) tool.
thank you.
2 comentarios
Geoff Hayes
el 14 de Nov. de 2014
Try using system or the exclamation point. An example of the latter and powershell seems to be found at How do I execute Powershell scripts in MATLAB.
Respuestas (1)
Greg
el 9 de Dic. de 2014
I'm not totally clear on what the actual question is. However, I'm taking a decent guess that your problem is the "echo" in your system command. In Windows system calls, "ECHO" is like MATLAB's "DISP". It purely prints the string back to you, there is no command being executed.
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!