Output Redirection with Start-Process for DB export


i'm trying call db export command using start-process powershell , capture of output.
i'm using powershell 2.0 on win2008 r2.
below various attempts i've made @ , notes on results.

i'm finding if use -redirectstandardoutput , -redirectstandarderror, nothing stdout , stderr capturing not of output (1479 lines - missing 40, maybe hitting line or memory limit?).
if try use unix-like redirects (2>&1>>logfile), initial line output handles, etc , invalid characters export lines should be, it's kind of encoding problem.  out-file , tee produce similar results.

i'm hoping might have insight why stdout , stderr seem reversed , if there limits stderr.  or if there method address encoding issue using unix redirects.

example of unix-like redirect output:
handles  npm(k)    pm(k)      ws(k) vm(m)   cpu(s)     id processname                                                  
-------  ------    -----      ----- -----   ------     -- -----------                                                  
     20       1      304        144     3     0.03  11640 expdp                                                        

〲㔱〭ⴹ㜱ㅔ㨴㌲㔺′㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽਍〲㔱〭ⴹ㜱ㅔ㨴㈴㔺‹ഠ㈊㄰ⴵ㤰ㄭ吷㐱㐺㨲㤵䐠瑡⽥楔敭椠⁳敓瑰浥敢⵲㜱ㄭ‵㨲㈴㔺‹䵐਍〲㔱〭ⴹ㜱ㅔ㨴㈴㔺‹捓楲瑰攠數畣楴杮椠⁳㩃潜獰扜湩睜灩扜湩扜捡畫彰灣捰瀮ㅳ਍〲㔱〭ⴹ㜱ㅔ㨴㈴㔺‹潌⁧楆敬慮敭椠⁳㩃潜獰扜湩睜灩汜杯扜捡畫彰灣捰氮杯਍〲㔱〭ⴹ㜱ㅔ㨴㈴㔺‹㴽㴽㴽㴽


variables used in snippets below avoid questions what's running.
$strexportexe = "c:\oracle\product\11.2.0\dbhome_1\bin\expdp.exe"
$strdate3 = get-date -format yyyymmdd_hh_mm_ss
$strexportfile = "${strinstance}_${strdate3}.exp"
$strarguments = "system/$strpwrd full=y directory=backup_dir dumpfile=$strexportfile"
$strbackuplog = "$stropslog\backup_cppc.log"
$strtmpbackupfile = "$stropstmp\tmp_backup_cppc.log"
funclogwrite function append lines main log file($strbackuplog) while adding date/time front of line

various attempts
1. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru -redirectstandardoutput $strbackuplog -redirectstandarderror $strtmpbackupfile
  - dumps into  stderror file & nothing in stdout file

2. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru 2>&1 >>$strbackuplog
  - doesn't log output screen, invalid characters in example above

3. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru 2>&1 -redirectstandardoutput $strbackuplog
  - no data in backup log, redirecting stderr stdout & sending stdout log file

4. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru 2>>$strbackuplog >>$strbackuplog
  - throws error "the process cannot access file 'c:\ops\log\backup_cppc.log' because being used process"
    because trying redirect both stderr (2>>) , stdout (>>) same file

5. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru 1>&2 -redirectstandarderror $strbackuplog
  - errors "the '1>&2' operator reserved future use."

6. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru >>$strbackuplog
  - same bad redirect 2nd 1 2>&1 >>$strbackuplog

7. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru | out-file $strbackuplog
  - outputs handles etc , invalid characters in example above

8. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru | tee-object -file $strbackuplog
  - same above invalid characters

9. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru -outvariable $out
   funclogwrite $out
  - combination sent nothing screen , nothing in $out being written log function funclogwrite

10. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru | tee $strbackuplog
  - same invalid characters in example above

11. $strstdout = "$stropslog\stdout.log"
    $strstderr = "$stropslog\stderr.log"
    $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru -redirectstandardoutput $strstdout -redirectstandarderror $strstderr
    funclogwrite "stdout db backup"
    funclogwrite "======="
    funccopyruntofulllog $strstdout
    funclogwrite "stderr db backup"
    funclogwrite "======="
    funccopyruntofulllog $strstderr

  - code above stdout file empty, stderr file has 1479 lines of output not of export info, missing 40 lines @ end of display on screen

12. $strprocess = start-process $strexportexe -argumentlist $strarguments -wait -nonewwindow -passthru 2>&1>>$strbackuplog
  - same 2. above removed space before log file @ end

after these attempted cmds, i've been using:
$strprocess.hasexited
$strprocess.exitcode
confirm it's finished , capture exitcode.  if other 0 alert issue db export.

you need take issue of how standard outputs use oracle.

using "unix" redirectors not same redirecting child process.  separate , unrelated issues.


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

DCOM received error "2147746132" from...

DFSR RPC replication errors 5014 1726 with large files over VPN

ADFS 3.0 Event ID 4625 | An Error occurred During Logon | Status: 0xC000035B