windowspowershellwincc-oa

How can i use system() with rxrepl in WinCC OA?


I try to use:

string result;
string path = "C:/winccoa.projects/filters/bin/tools/rxrepl.exe";
string cmd = "'opcki' | " + path + " -s 'op' -r 'tata'";
system(cmd, result);
DebugN(result);

But in LogViewer i see nothing, instead ["tatacki"]

Why? What i doing wrong?

In PowerShell that works fine:

PS C:\> 'opcki' | C:/winccoa.projects/filters/bin/tools/rxrepl.exe -s "op" -r "tata"
tatacki

Solution

  • I'm assuming that WinCC's system() function targets cmd.exe, not powershell.exe (which is typical, because historically cmd.exe has been the default shell, and APIs are unlikely to change, so as to maintain backward compatibility).

    Therefore, formulate your command for cmd.exe:

    string cmd = "echo opcki | " + path + " -s op -r tata";
    

    Not the use of echo to produce output and the omission of single-quoting ('...'), which cmd.exe doesn't recognize.

    If embedded quoting were needed, you'd have to use `" inside "..." PowerShell strings (or use '...' PowerShell strings (whose content is taken literally) and embed " chars. as-is).