powershell Start Transcript作用域


PowerShell交流中心分类: Powershell基础powershell Start Transcript作用域
0
momoko_glad asked 7年 ago

在powershell中,Start Transcript可以将屏幕输出的信息保存至指定的文件中,

但是如果A脚本调用了B脚本和一个自定义DLL:C,且两个脚本和DLL中均有屏幕输出的话,

若在A脚本中设置了Start Transcript,好像只能作用到本脚本,B脚本和自定义DLL C中的

屏幕输出似乎不能一起写入指定文件。有没有解决办法呢,拜托拜托。

1 Answers
1
Mooser Lee 管理员 answered 7年 ago

你说的问题,我重新不了:
我的A脚本:

Start-Transcript a.txt
"我是A"
E:\ps\CTClient\B.ps1
Stop-Transcript

我的B脚本:

"我是B"

我的日志:

**********************
Windows PowerShell transcript start
Start time: 20170302121143
Username: PStips.NET\mosser
RunAs User: PStips.NET\mosser
Machine: PSTtips (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe
Process ID: 8692
PSVersion: 5.0.10586.117
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0.10586.117
BuildVersion: 10.0.10586.117
CLRVersion: 4.0.30319.36373
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
我是A
我是B
**********************
Windows PowerShell transcript end
End time: 20170302121143
**********************

 
 

momoko_glad replied 7年 ago

我的A脚本:
Start-Transcript f:\a.txt
“我是A”
Start-Process -FilePath powershell.exe -ArgumentList “E:\b.ps1” -WindowStyle Hidden
Stop-Transcript

我的B脚本:
“我是B”

我的日志:
**********************
Windows PowerShell トランスクリプト開始
開始時刻: 20170302144246
ユーザー名 : DEP3-PC2\Administrator
コンピューター : DEP3-PC2 (Microsoft Windows NT 6.3.9600.0)
**********************
トランスクリプトが開始されました。出力ファイル: f:\a.txt
我是A
**********************
Windows PowerShell トランスクリプト終了
終了時刻: 20170302144246
**********************

我在调用B时重新开了一个进程,这样好像就获取不到B所输出的信息了
还有就是如果用同一个进程时,我在B中调用了 C.dll, C所输出的信息 也是获取不了的,大神求解惑。

另外还有一个问题请教下
try{
Write-Host “P1 = 1”
E:\temp1.ps1 #
}
catch [Exception]{
Write-Host (‘Error occured: ‘ + $_.Exception.Message)
}finally{

}
我想获得上述代码异常场合时的异常code,并不是异常信息,请问怎么改,跪等中。。。。。。

Mooser Lee 管理员 replied 7年 ago

你用了Start-Process,这样是相当于重新开了一个Windows PowerShell控制台,这样跨进程的,自然记录不到了。

momoko_glad replied 7年 ago

用powershell调用dll,在dll中打印的控制台信息,怎么写到文件中
Start-Transcrip 好像不能将dll中打印的控制台信息,写到指定文件中

momoko_glad replied 7年 ago

用powershell调用dll,在dll中打印的控制台信息,怎么写到文件中
Start-Transcrip 好像不能将dll中打印的控制台信息,写到指定文件中