2014-02-19 50 views
1

我在一個文件夾中有很多oracle表單,我想通過powershell腳本中的frmcmp命令編譯這些表單。使用powershell腳本編譯oracle表格

我已經寫了這是繼

$module="module=" 
    get-childitem "C:\forms\fortest" -recurse | 
     where { $_.extension -eq ".fmb" } | 
     foreach { 
      C:\Oracle\Middleware\Oracle_FRHome1\BIN\frmcmp $module $_.FullName userid=xyz/[email protected] Output_File=C:\forms\11\common\fmx\$_.BaseName+'.fmx' 
     } 

PowerShell腳本,但這一個不工作。我是Powerhell的新手。

但是當我嘗試通過命令提示符編譯單個表單時,它的工作方式如下。

frmcmp module=C:\forms\src\xyz.fmb userid=xyz/[email protected] Output_File=C:\forms\11\common\fmx\xyz.fmx 
+0

你是什麼意思的「不工作」?錯誤信息?沒有結果?完全不同的東西? – vonPryz

+0

其不工作意味着: - 沒有結果 – p27

回答

2

當您想在PowerShell中的字符串中使用變量時,您有不同的選項。首先,如果需要字符串中的變量,您將始終需要使用"而不是'來包裝字符串。

$myVariable = "MyPropertyValue" 
Write-Host "The variable has the value $MyVariable" 

上面的代碼將產生的輸出:如果要使用的變量的屬性(或任何表達式),其插入到串

The variable has the value MyPropertyValue 

,需要包裝在帶有$(expression goes here)的字符串,例如

$MyVariable = New-Object PSObject -Property @{ MyPropertyName = 'MyPropertyValue' } 

# The following will fail getting the property since it will only consider 
# the variable name as code, not the dot or the property name. It will 
# therefore ToString the object and append the literal string .MyPropertyName 
Write-Host "Failed property value retrieval: $MyVariable.MyPropertyName" 

# This will succeed, since it's wrapped as code. 
Write-Host "Successful property value retrieval: $($MyVariable.MyPropertyName)" 

# You can have any code in those wrappers, for example math. 
Write-Host "Maths calculating: 3 * 27 = $(3 * 27)" 

上面的代碼會產生以下輸出:

Failed property value retrieval: @{MyPropertyName=MyPropertyValue}.MyPropertyName 
Successful property value retrieval: MyPropertyValue 
Maths calculating: 3 * 27 = 81 

我一般儘量當我在PowerShell中啓動進程,因爲它給了我更多的控制權的過程中可能使用的Start-Process cmdlet的開始。這意味着您可以使用類似於以下內容的內容。

Get-ChildItem "C:\forms\fortest" -Filter "*.fmb" -recurse | Foreach { 
    $FormPath = $_.FullName 
    $ResultingFileName = $_.BaseName 
    Start-Process -FilePath "C:\Oracle\Middleware\Oracle_FRHome1\BIN\frmcmp.exe" -ArgumentList "module=$FormPath", "userid=xyz/[email protected]", "Output_File=C:\forms\11\common\fmx\$ResultingFileName.fmx" 
} 

您也可以在-Wait參數添加到開始處理命令,如果你想與下一個項目的編制要等到當前編譯完成。

+0

感謝您的快速回復。 – p27