WeixiangYan/CodeTransOcean huggingface dataset:
Task: Convert seconds to compound duration



C#: using System;
using System.Collections.Generic;
using System.Linq;

namespace ConvertSecondsToCompoundDuration
{
  class Program
  {
    static void Main( string[] args )
    {
      foreach ( string arg in args )
      {
        int duration ;
        bool isValid = int.TryParse( arg , out duration ) ;

        if ( !isValid     ) { Console.Error.WriteLine( "ERROR: Not an integer: {0}"           , arg ) ; }
        if ( duration < 0 ) { Console.Error.WriteLine( "ERROR: duration must be non-negative" , arg ) ; }
        
        Console.WriteLine();
        Console.WriteLine( "{0:#,##0} seconds ==> {1}" , duration , FormatAsDuration(duration) ) ;
        
      }
    }
    
    private static string FormatAsDuration( int duration )
    {
      if ( duration < 0 ) throw new ArgumentOutOfRangeException("duration") ;
      return string.Join( ", " , GetDurationParts(duration)  ) ;
    }
    
    private static IEnumerable<string> GetDurationParts( int duration )
    {
      var parts = new[]
      {
        new { Name="wk" , Length = 7*24*60*60*1 , } ,
        new { Name="d"  , Length =   24*60*60*1 , } ,
        new { Name="h"  , Length =      60*60*1 , } ,
        new { Name="m"  , Length =         60*1 , } ,
        new { Name="s"  , Length =            1 , } ,
      } ;
      
      foreach ( var part in parts )
      {
        int n = Math.DivRem( duration , part.Length , out duration ) ;
        if ( n > 0 ) yield return string.Format( "{0} {1}" , n , part.Name ) ;
      }
      
    }
    
  }
  
}








Fortran:       SUBROUTINE PROUST(T)	
       INTEGER T		
       INTEGER NTYPES		
       PARAMETER (NTYPES = 5)	
       INTEGER USIZE(NTYPES)	
       CHARACTER*3 UNAME(NTYPES)
       PARAMETER (USIZE = (/7*24*60*60, 24*60*60, 60*60,   60,    1/))	
       PARAMETER (UNAME = (/      "wk",      "d",  "hr","min","sec"/))	
       CHARACTER*28 TEXT	
       INTEGER I,L,N,S		
        S = T			
        L = 0			
        DO I = 1,NTYPES		
          N = S/USIZE(I)	
          IF (N.GT.0) THEN	
            S = S - N*USIZE(I)		
            IF (L.GT.0) THEN		
              L = L + 2				
              TEXT(L - 1:L) = ", "		
            END IF			
            WRITE (TEXT(L + 1:),1) N,UNAME(I)	
    1       FORMAT (I0,1X,A)		
            L = LEN_TRIM(TEXT)		
          END IF			
        END DO			
Cast forth the result.
        WRITE (6,*) T,">",TEXT(1:L),"<"	
       END			

       PROGRAM MARCEL		
       CALL PROUST(7259)
       CALL PROUST(7260)
       CALL PROUST(86400)
       CALL PROUST(6000000)
       CALL PROUST(0)
       CALL PROUST(-666)
       END
Task: Convert seconds to compound duration


C++: #include <iostream>
#include <vector>

using entry = std::pair<int, const char*>;

void print(const std::vector<entry>& entries, std::ostream& out = std::cout)
{
    bool first = true;
    for(const auto& e: entries) {
        if(!first) out << ", ";
        first = false;
        out << e.first << " " << e.second;
    }
    out << '\n';
}

std::vector<entry> convert(int seconds)
{
    static const entry time_table[] = {
        {7*24*60*60, "wk"}, {24*60*60, "d"}, {60*60, "hr"}, {60, "min"}, {1, "sec"}
    };
    std::vector<entry> result;
    for(const auto& e: time_table) {
        int time = seconds / e.first;
        if(time != 0) result.emplace_back(time, e.second);
        seconds %= e.first;
    }
    return result;
}

int main()
{
    std::cout << "   7259 sec is "; print(convert(   7259));
    std::cout << "  86400 sec is "; print(convert(  86400));
    std::cout << "6000000 sec is "; print(convert(6000000));
}









Fortran:       SUBROUTINE PROUST(T)	
       INTEGER T		
       INTEGER NTYPES		
       PARAMETER (NTYPES = 5)	
       INTEGER USIZE(NTYPES)	
       CHARACTER*3 UNAME(NTYPES)
       PARAMETER (USIZE = (/7*24*60*60, 24*60*60, 60*60,   60,    1/))	
       PARAMETER (UNAME = (/      "wk",      "d",  "hr","min","sec"/))	
       CHARACTER*28 TEXT	
       INTEGER I,L,N,S		
        S = T			
        L = 0			
        DO I = 1,NTYPES		
          N = S/USIZE(I)	
          IF (N.GT.0) THEN	
            S = S - N*USIZE(I)		
            IF (L.GT.0) THEN		
              L = L + 2				
              TEXT(L - 1:L) = ", "		
            END IF			
            WRITE (TEXT(L + 1:),1) N,UNAME(I)	
    1       FORMAT (I0,1X,A)		
            L = LEN_TRIM(TEXT)		
          END IF			
        END DO			
Cast forth the result.
        WRITE (6,*) T,">",TEXT(1:L),"<"	
       END			

       PROGRAM MARCEL		
       CALL PROUST(7259)
       CALL PROUST(7260)
       CALL PROUST(86400)
       CALL PROUST(6000000)
       CALL PROUST(0)
       CALL PROUST(-666)
       END
Task: Convert seconds to compound duration

C: 

#define _CRT_SECURE_NO_WARNINGS 

#include <stdio.h>
#include <stdlib.h>


char* seconds2string(unsigned long seconds) 
{
    int i;

    const unsigned long s =  1;
    const unsigned long m = 60 * s;
    const unsigned long h = 60 * m;
    const unsigned long d = 24 * h;
    const unsigned long w =  7 * d;

    const unsigned long coeff[5] = { w, d, h, m, s };
    const char units[5][4] = { "wk", "d", "hr", "min", "sec" };

    static char buffer[256];
    char* ptr = buffer;

    for ( i = 0; i < 5; i++ )
    {
        unsigned long value;
        value   = seconds / coeff[i];
        seconds = seconds % coeff[i];
        if ( value )
        {
            if ( ptr != buffer ) 
                ptr += sprintf(ptr, ", ");
            ptr += sprintf(ptr,"%lu %s",value,units[i]);
        }
    }

    return buffer;
}


int main(int argc, char argv[])
{
    unsigned long seconds;

    if ( (argc <  2) && scanf( "%lu", &seconds ) 
    ||   (argc >= 2) && sscanf( argv[1], "%lu", & seconds ) )
    {
        printf( "%s\n", seconds2string(seconds) );
        return EXIT_SUCCESS;
    }

    return EXIT_FAILURE;
}










Fortran:       SUBROUTINE PROUST(T)	
       INTEGER T		
       INTEGER NTYPES		
       PARAMETER (NTYPES = 5)	
       INTEGER USIZE(NTYPES)	
       CHARACTER*3 UNAME(NTYPES)
       PARAMETER (USIZE = (/7*24*60*60, 24*60*60, 60*60,   60,    1/))	
       PARAMETER (UNAME = (/      "wk",      "d",  "hr","min","sec"/))	
       CHARACTER*28 TEXT	
       INTEGER I,L,N,S		
        S = T			
        L = 0			
        DO I = 1,NTYPES		
          N = S/USIZE(I)	
          IF (N.GT.0) THEN	
            S = S - N*USIZE(I)		
            IF (L.GT.0) THEN		
              L = L + 2				
              TEXT(L - 1:L) = ", "		
            END IF			
            WRITE (TEXT(L + 1:),1) N,UNAME(I)	
    1       FORMAT (I0,1X,A)		
            L = LEN_TRIM(TEXT)		
          END IF			
        END DO			
Cast forth the result.
        WRITE (6,*) T,">",TEXT(1:L),"<"	
       END			

       PROGRAM MARCEL		
       CALL PROUST(7259)
       CALL PROUST(7260)
       CALL PROUST(86400)
       CALL PROUST(6000000)
       CALL PROUST(0)
       CALL PROUST(-666)
       END
Task: Convert seconds to compound duration





Java: public class CompoundDuration {

    public static void main(String[] args) {
        compound(7259);
        compound(86400);
        compound(6000_000);
    }

    private static void compound(long seconds) {
        StringBuilder sb = new StringBuilder();

        seconds = addUnit(sb, seconds, 604800, " wk, ");
        seconds = addUnit(sb, seconds, 86400, " d, ");
        seconds = addUnit(sb, seconds, 3600, " hr, ");
        seconds = addUnit(sb, seconds, 60, " min, ");
        addUnit(sb, seconds, 1, " sec, ");

        sb.setLength(sb.length() > 2 ? sb.length() - 2 : 0);

        System.out.println(sb);
    }

    private static long addUnit(StringBuilder sb, long sec, long unit, String s) {
        long n;
        if ((n = sec / unit) > 0) {
            sb.append(n).append(s);
            sec %= (n * unit);
        }
        return sec;
    }
}






Fortran:       SUBROUTINE PROUST(T)	
       INTEGER T		
       INTEGER NTYPES		
       PARAMETER (NTYPES = 5)	
       INTEGER USIZE(NTYPES)	
       CHARACTER*3 UNAME(NTYPES)
       PARAMETER (USIZE = (/7*24*60*60, 24*60*60, 60*60,   60,    1/))	
       PARAMETER (UNAME = (/      "wk",      "d",  "hr","min","sec"/))	
       CHARACTER*28 TEXT	
       INTEGER I,L,N,S		
        S = T			
        L = 0			
        DO I = 1,NTYPES		
          N = S/USIZE(I)	
          IF (N.GT.0) THEN	
            S = S - N*USIZE(I)		
            IF (L.GT.0) THEN		
              L = L + 2				
              TEXT(L - 1:L) = ", "		
            END IF			
            WRITE (TEXT(L + 1:),1) N,UNAME(I)	
    1       FORMAT (I0,1X,A)		
            L = LEN_TRIM(TEXT)		
          END IF			
        END DO			
Cast forth the result.
        WRITE (6,*) T,">",TEXT(1:L),"<"	
       END			

       PROGRAM MARCEL		
       CALL PROUST(7259)
       CALL PROUST(7260)
       CALL PROUST(86400)
       CALL PROUST(6000000)
       CALL PROUST(0)
       CALL PROUST(-666)
       END
Task: Convert seconds to compound duration







Python: >>> def duration(seconds):
	t= []
	for dm in (60, 60, 24, 7):
		seconds, m = divmod(seconds, dm)
		t.append(m)
	t.append(seconds)
	return ', '.join('%d %s' % (num, unit)
			 for num, unit in zip(t[::-1], 'wk d hr min sec'.split())
			 if num)

>>> for seconds in [7259, 86400, 6000000]:
	print("%7d sec = %s" % (seconds, duration(seconds)))

	
   7259 sec = 2 hr, 59 sec
  86400 sec = 1 d
6000000 sec = 9 wk, 6 d, 10 hr, 40 min
>>>




Fortran:       SUBROUTINE PROUST(T)	
       INTEGER T		
       INTEGER NTYPES		
       PARAMETER (NTYPES = 5)	
       INTEGER USIZE(NTYPES)	
       CHARACTER*3 UNAME(NTYPES)
       PARAMETER (USIZE = (/7*24*60*60, 24*60*60, 60*60,   60,    1/))	
       PARAMETER (UNAME = (/      "wk",      "d",  "hr","min","sec"/))	
       CHARACTER*28 TEXT	
       INTEGER I,L,N,S		
        S = T			
        L = 0			
        DO I = 1,NTYPES		
          N = S/USIZE(I)	
          IF (N.GT.0) THEN	
            S = S - N*USIZE(I)		
            IF (L.GT.0) THEN		
              L = L + 2				
              TEXT(L - 1:L) = ", "		
            END IF			
            WRITE (TEXT(L + 1:),1) N,UNAME(I)	
    1       FORMAT (I0,1X,A)		
            L = LEN_TRIM(TEXT)		
          END IF			
        END DO			
Cast forth the result.
        WRITE (6,*) T,">",TEXT(1:L),"<"	
       END			

       PROGRAM MARCEL		
       CALL PROUST(7259)
       CALL PROUST(7260)
       CALL PROUST(86400)
       CALL PROUST(6000000)
       CALL PROUST(0)
       CALL PROUST(-666)
       END
Task: Convert seconds to compound duration








VB: Private Function compound_duration(ByVal seconds As Long) As String
    minutes = 60
    hours = 60 * minutes
    days_ = 24 * hours
    weeks = 7 * days_
    Dim out As String
    w = seconds \ weeks
    seconds = seconds - w * weeks
    d = seconds \ days_
    seconds = seconds - d * days_
    h = seconds \ hours
    seconds = seconds - h * hours
    m = seconds \ minutes
    s = seconds Mod minutes
    out = IIf(w > 0, w & " wk, ", "") & _
        IIf(d > 0, d & " d, ", "") & _
        IIf(h > 0, h & " hr, ", "") & _
        IIf(m > 0, m & " min, ", "") & _
        IIf(s > 0, s & " sec", "")
    If Right(out, 2) = ", " Then
        compound_duration = Left(out, Len(out) - 2)
    Else
        compound_duration = out
    End If
End Function

Public Sub cstcd()
    Debug.Print compound_duration(7259)
    Debug.Print compound_duration(86400)
    Debug.Print compound_duration(6000000)
End Sub



Fortran:       SUBROUTINE PROUST(T)	
       INTEGER T		
       INTEGER NTYPES		
       PARAMETER (NTYPES = 5)	
       INTEGER USIZE(NTYPES)	
       CHARACTER*3 UNAME(NTYPES)
       PARAMETER (USIZE = (/7*24*60*60, 24*60*60, 60*60,   60,    1/))	
       PARAMETER (UNAME = (/      "wk",      "d",  "hr","min","sec"/))	
       CHARACTER*28 TEXT	
       INTEGER I,L,N,S		
        S = T			
        L = 0			
        DO I = 1,NTYPES		
          N = S/USIZE(I)	
          IF (N.GT.0) THEN	
            S = S - N*USIZE(I)		
            IF (L.GT.0) THEN		
              L = L + 2				
              TEXT(L - 1:L) = ", "		
            END IF			
            WRITE (TEXT(L + 1:),1) N,UNAME(I)	
    1       FORMAT (I0,1X,A)		
            L = LEN_TRIM(TEXT)		
          END IF			
        END DO			
Cast forth the result.
        WRITE (6,*) T,">",TEXT(1:L),"<"	
       END			

       PROGRAM MARCEL		
       CALL PROUST(7259)
       CALL PROUST(7260)
       CALL PROUST(86400)
       CALL PROUST(6000000)
       CALL PROUST(0)
       CALL PROUST(-666)
       END
Task: Convert seconds to compound duration







Python: >>> def duration(seconds):
	t= []
	for dm in (60, 60, 24, 7):
		seconds, m = divmod(seconds, dm)
		t.append(m)
	t.append(seconds)
	return ', '.join('%d %s' % (num, unit)
			 for num, unit in zip(t[::-1], 'wk d hr min sec'.split())
			 if num)

>>> for seconds in [7259, 86400, 6000000]:
	print("%7d sec = %s" % (seconds, duration(seconds)))

	
   7259 sec = 2 hr, 59 sec
  86400 sec = 1 d
6000000 sec = 9 wk, 6 d, 10 hr, 40 min
>>>



COBOL:        identification division.
       program-id. fmt-dura.
       data division.
       working-storage section.
       1 input-seconds pic 9(8).
       1 formatted-duration pic x(30) global.
       1 fractions.
        2 weeks pic z(3)9.
        2 days pic z(3)9.
        2 hours pic z(3)9.
        2 minutes pic z(3)9.
        2 seconds pic z(3)9.
       1 .
        2 weeks-str pic x(4) value "wk".
        2 days-str pic x(4) value "d".
        2 hours-str pic x(4) value "hr".
        2 minutes-str pic x(4) value "min".
        2 seconds-str pic x(4) value "sec".
       1 work binary global.
        2 str-pos pic 9(4).
        2 chars-transferred pic 9(4).
       procedure division.
       begin.
           display "Enter duration (seconds): " no advancing
           accept input-seconds
           divide input-seconds by 60 giving input-seconds
               remainder seconds
           divide input-seconds by 60 giving input-seconds
               remainder minutes
           divide input-seconds by 24 giving input-seconds
               remainder hours
           divide input-seconds by 7 giving weeks
               remainder days
           move 1 to str-pos
           call "fmt" using weeks weeks-str
           call "fmt" using days days-str
           call "fmt" using hours hours-str
           call "fmt" using minutes minutes-str
           call "fmt" using seconds seconds-str
           display formatted-duration
           stop run
           .

       identification division.
       program-id. fmt.
       data division.
       working-storage section.
       77 nothing pic x.
       linkage section.
       1 formatted-value pic x(4).
       1 duration-size pic x(4).
       procedure division using formatted-value duration-size.
       begin.
           if function numval (formatted-value) not = 0
               perform insert-comma-space
               unstring formatted-value delimited all space
                   into nothing formatted-duration (str-pos:)
                   count chars-transferred
               add chars-transferred to str-pos
               string space delimited size
                   duration-size delimited space
                   into formatted-duration pointer str-pos
           end-if
           exit program
           .

       insert-comma-space.
           if str-pos > 1
               move ", " to formatted-duration (str-pos:)
               add 2 to str-pos
           end-if
           .
       end program fmt.
       end program fmt-dura.
Task: Execute a system command



C#: using System.Diagnostics;

namespace Execute
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("cmd.exe", "/c dir");
        }
    }
}









Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command

C: #include <stdlib.h>

int main()
{
    system("ls");
    return 0;
}











Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command


C++: system("pause");










Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command




Go: package main

import (
    "log"
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("ls", "-l")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
}








Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command





Java: import java.util.Scanner;
import java.io.*;

public class Program {
    public static void main(String[] args) {    	
    	try {
    		Process p = Runtime.getRuntime().exec("cmd /C dir");
    		Scanner sc = new Scanner(p.getInputStream());    		
    		while (sc.hasNext()) System.out.println(sc.nextLine());
    	}
    	catch (IOException e) {
    		System.out.println(e.getMessage());
    	}
    }
}







Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command







Python: import os
exit_code = os.system('ls')       
output    = os.popen('ls').read() 





Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command








VB: Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /K dir",3,True




Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Execute a system command



C#: using System.Diagnostics;

namespace Execute
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("cmd.exe", "/c dir");
        }
    }
}
Task: Execute a system command





Java: import java.util.Scanner;
import java.io.*;

public class Program {
    public static void main(String[] args) {    	
    	try {
    		Process p = Runtime.getRuntime().exec("cmd /C dir");
    		Scanner sc = new Scanner(p.getInputStream());    		
    		while (sc.hasNext()) System.out.println(sc.nextLine());
    	}
    	catch (IOException e) {
    		System.out.println(e.getMessage());
    	}
    }
}
Task: Execute a system command




Go: package main

import (
    "log"
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("ls", "-l")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
}
Task: Execute a system command

C: #include <stdlib.h>

int main()
{
    system("ls");
    return 0;
}
Task: Execute a system command







Python: import os
exit_code = os.system('ls')       
output    = os.popen('ls').read()
Task: Execute a system command








VB: Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /K dir",3,True
Task: Execute a system command


C++: system("pause");
Task: Execute a system command



C#: using System.Diagnostics;

namespace Execute
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("cmd.exe", "/c dir");
        }
    }
}








Fortran: program SystemTest
integer :: i
 call execute_command_line ("ls", exitstat=i)
end program SystemTest
Task: Execute a system command

C: #include <stdlib.h>

int main()
{
    system("ls");
    return 0;
}










Fortran: program SystemTest
integer :: i
 call execute_command_line ("ls", exitstat=i)
end program SystemTest
Task: Execute a system command





Java: import java.util.Scanner;
import java.io.*;

public class Program {
    public static void main(String[] args) {    	
    	try {
    		Process p = Runtime.getRuntime().exec("cmd /C dir");
    		Scanner sc = new Scanner(p.getInputStream());    		
    		while (sc.hasNext()) System.out.println(sc.nextLine());
    	}
    	catch (IOException e) {
    		System.out.println(e.getMessage());
    	}
    }
}






Fortran: program SystemTest
integer :: i
 call execute_command_line ("ls", exitstat=i)
end program SystemTest
Task: Execute a system command







Python: import os
exit_code = os.system('ls')       
output    = os.popen('ls').read() 




Fortran: program SystemTest
integer :: i
 call execute_command_line ("ls", exitstat=i)
end program SystemTest
Task: Execute a system command








VB: Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /K dir",3,True



Fortran: program SystemTest
integer :: i
 call execute_command_line ("ls", exitstat=i)
end program SystemTest
Task: Execute a system command






PHP: @exec($command,$output);
echo nl2br($output);





Fortran: program SystemTest
integer :: i
 call execute_command_line ("ls", exitstat=i)
end program SystemTest
Task: Execute a system command

C: #include <stdlib.h>

int main()
{
    system("ls");
    return 0;
}









COBOL: CALL "SYSTEM" USING BY CONTENT "ls"
Task: Execute a system command



C#: using System.Diagnostics;

namespace Execute
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("cmd.exe", "/c dir");
        }
    }
}







COBOL: CALL "SYSTEM" USING BY CONTENT "ls"
Task: Execute a system command





Java: import java.util.Scanner;
import java.io.*;

public class Program {
    public static void main(String[] args) {    	
    	try {
    		Process p = Runtime.getRuntime().exec("cmd /C dir");
    		Scanner sc = new Scanner(p.getInputStream());    		
    		while (sc.hasNext()) System.out.println(sc.nextLine());
    	}
    	catch (IOException e) {
    		System.out.println(e.getMessage());
    	}
    }
}





COBOL: CALL "SYSTEM" USING BY CONTENT "ls"
Task: Execute a system command







Python: import os
exit_code = os.system('ls')       
output    = os.popen('ls').read() 



COBOL: CALL "SYSTEM" USING BY CONTENT "ls"
Task: Execute a system command








VB: Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /K dir",3,True


COBOL: CALL "SYSTEM" USING BY CONTENT "ls"
Task: Execute a system command




Go: package main

import (
    "log"
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("ls", "-l")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
}






COBOL: CALL "SYSTEM" USING BY CONTENT "ls"
Task: Execute a system command






PHP: @exec($command,$output);
echo nl2br($output);
Task: Execute a system command






PHP: @exec($command,$output);
echo nl2br($output);






Ada: with POSIX.Unsafe_Process_Primitives;

procedure Execute_A_System_Command is
   Arguments : POSIX.POSIX_String_List;
begin
   POSIX.Append (Arguments, "ls");
   POSIX.Unsafe_Process_Primitives.Exec_Search ("ls", Arguments);
end Execute_A_System_Command;
Task: Loops_Do-while



C#: int a = 0;

do
{
    a += 1;
    Console.WriteLine(a);
} while (a % 6 != 0);









Ada: loop
   Value := Value + 1;
   Put (Value);
   exit when Value mod 6 = 0;
end loop;
Task: Loops_Do-while

C: int val = 0;
do{
   val++;
   printf("%d\n",val);
}while(val % 6 != 0);











Ada: loop
   Value := Value + 1;
   Put (Value);
   exit when Value mod 6 = 0;
end loop;
Task: Loops_Do-while


C++: int val = 0;
do{
   val++;
   std::cout << val << std::endl;
}while(val % 6 != 0);










Ada: loop
   Value := Value + 1;
   Put (Value);
   exit when Value mod 6 = 0;
end loop;