我试图让matlab和ImageJ在批处理文件中的for循环中工作。
代码是这样的
$SecurePassword = $accPassword | ConvertTo-SecureString -AsPlainText -Force
$credential = new-object -typename System.Management.Automation.PSCredential ($username, $SecurePassword)
#Login-AzureRmAccount -Credential $credential
Add-AzureRmAccount -Credential $credential
"Script is started"
## Global
$ResourceGroupName = "linux_vm_resource"
$Location = "Central India"
## Storage
$StorageName = "linuxvmstorageac"
$StorageType = "Standard_GRS"
## Network
$InterfaceName = "ServerInterface06"
$Subnet1Name = "Subnet1"
$VNetName = "linux_vm_vnet"
$VNetAddressPrefix = "10.0.0.0/16"
$VNetSubnetAddressPrefix = "10.0.0.0/24"
## Compute
$VMName = "LinuxMigrateVm"
$VMSize = "Standard_F1S"
$OSDiskName = $VMName + "OSDisk1"
# Resource Group
$resourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -ea SilentlyContinue
if(!$resourceGroup){
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
}
# Storage
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageName
if(!$StorageAccount){
$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -Type $StorageType -Location $Location
}
# Network
$PIp = Get-AzureRmPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -ea SilentlyContinue
if(!$PIp){
$PIp = New-AzureRmPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Dynamic
}
## Create Network Security Group
$nsg = Get-AzureRmNetworkSecurityGroup -Name "myNetworkSecurityGroup"-ResourceGroupName $ResourceGroupName
if(!$nsg){
$httprule1 = New-AzureRmNetworkSecurityRuleConfig -Name "default-allow-ssh" `
-Description "Allow HTTP" -Access "Allow" -Protocol "TCP" -Direction "Inbound" `
-Priority "1000" -SourceAddressPrefix * -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 22
$httprule2 = New-AzureRmNetworkSecurityRuleConfig -Name "ftp_client" `
-Description "Allow HTTP" -Access "Allow" -Protocol "TCP" -Direction "Inbound" `
-Priority "1010" -SourceAddressPrefix * -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 21
$httprule3 = New-AzureRmNetworkSecurityRuleConfig -Name "all" `
-Description "Allow HTTP" -Access "Allow" -Protocol "TCP" -Direction "Outbound" `
-Priority "100" -SourceAddressPrefix * -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 21
$httprule4 = New-AzureRmNetworkSecurityRuleConfig -Name "ssh" `
-Description "Allow HTTP" -Access "Allow" -Protocol "TCP" -Direction "Outbound" `
-Priority "110" -SourceAddressPrefix * -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 22
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $ResourceGroupName `
-Location $Location -Name "myNetworkSecurityGroup" -SecurityRules $httprule1,$httprule2,$httprule3,$httprule4
}
$SubnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name $Subnet1Name -AddressPrefix $VNetSubnetAddressPrefix -NetworkSecurityGroup $nsg
$VNet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName
if(!$VNet){
$VNet = New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig
}
$Interface = Get-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName
if(!$Interface){
$Interface = New-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PIp.Id
}
# Compute
## Setup local VM object
$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName $VMName -Credential $Credential
$VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "16.10" -Version "latest"
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd"
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -CreateOption FromImage
## Create the VM in Azure
$vM = Get-AzureRmVM -ResourceGroupName $ResourceGroupName
if(!$vM){
$vM = New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine
}
我指定了变量,问题是ImageJ需要使用matlab代码的输出,但批处理似乎在同一时间执行ImageJ和Matlab ...
我已经使用调用来使迭代变量工作,在两句话之前添加另一个调用无济于事。
那么如何在matlab运行完毕后首先执行matlab并运行ImageJ?
谢谢!!!!
答案 0 :(得分:0)
问题是您需要使用matlabs wait option。您不使用cmd.exe的CALL
或START /WAIT
命令。
set iterationTimes=4
for /l %%i in (0,1,%iterationTimes%) do (
matlab -wait -nodesktop -nosplash -r "loop=%%i;"%stitchFile%
call %IJPath% -macro %JythonPath% %%arg%%
)