0

How to fix truncated output java from a powershell command. When i execute my command line directly from cmd i get this results

powershell C:\CMDLETS\getaccountattributes.ps1    
Key                 Value
---                               -----    
address2_county 7d8b4132e6a6e44682046b524f3904ca@O=IAM;
15dc3a803c4012479db49b28c9e590c5@O=IAM    
systemuserid a418a064-a1ed-e811-80e9-005056bd633b    
accessmode  Microsoft.Xrm.Sdk.OptionSetValue

but when i run this in java:

    ExecuteShellComand executeshellecomand = new ExecuteShellComand();
    String command = "powershell C:\\CMDLETS\\getaccountattributes.ps1"; 
    log.info("avant exctuion du shell");
    String output = executeshellecomand.executeCommand(command);
    log.info("Val of output " +output);
    BufferedReader reader = new BufferedReader( new StringReader(output) )



String executeCommand(String command) {

    StringBuffer output = new StringBuffer();
    StringBuffer outputError = new StringBuffer();


    Process p;
    try {
        p = Runtime.getRuntime().exec(command);
        log.info("runtime powerhsel "+ p.getInputStream().toString());
        int test= p.waitFor();

        String line = "", errorLine = "" ;
        BufferedReader reader =
                       new BufferedReader(new InputStreamReader(p.getInputStream()));

        BufferedReader errinput = new BufferedReader(new InputStreamReader(
                p.getErrorStream()));

        while ((line = reader.readLine())!= null) {
            output.append(line + "\n");

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return output.toString();

Results :
Key                               Value                                        
---                               -----                                        
address2_county                   7d8b4132e6a6e44682046b524f3904ca@O=IAM;15d...

systemuserid                      a418a064-a1ed-e811-80e9-005056bd633b         
accessmode                        Microsoft.Xrm.Sdk.OptionSetValue 

the first attribute was truncated. How do i get my desired result please. Thanks!

Aminfo
  • 23
  • 9
  • I think it is not just truncated but also different. – Bahadir Tasdemir Dec 02 '18 at 17:41
  • It shouldn't be different. It's the same powershell – Aminfo Dec 02 '18 at 21:16
  • Looks to me the first output example was displayed using the `-Wrap` parameter on the `Format-Table` cmdlet and the second one did not use `-Wrap`. (Displays text that exceeds the column width on the next line. By default, text that exceeds the column width is truncated.) – Theo Dec 03 '18 at 10:24
  • Looks like your first output are just strings. The second output are objects. Could you post your getaccountattributes.ps1 code for us to inspect? Thanks. – Peter Kay Dec 03 '18 at 22:25

1 Answers1

0

It works with piping to export-csv

powershell C:\CMDLETS\getaccountattributes.ps1 | Export-csv C:\CMDLETS\getaccountattributes.csv

Aminfo
  • 23
  • 9