2014-02-19 55 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