Calling Powershell from MATLAB: AWS Example

9 次查看(过去 30 天)
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 个评论
Matlab2010
Matlab2010 2014-11-18
temp answer: You need to write bat files that speak to aws powershell (which does not have an exe, only a dll). system.m then calls the bat file. to be updated when ive got it working...

请先登录,再进行评论。

回答(1 个)

Greg
Greg 2014-12-9
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.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by