S
H
A
R
E
Showing posts with label Console. Show all posts
Showing posts with label Console. Show all posts

Saturday, February 11, 2012

Java Execute Console Process and Get Output

To execute process you can use ProcessBuilder, like this:

ProcessBuilder pb = new ProcessBuilder("tasklist").redirectErrorStream(true);

use redirectErrorStream to make the BufferedReader can read if error message is returned.

Now, get the Process by executing it:
Process p = pb.start();
  
Then make a BufferedReader that can read the console output screen:
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

You can read the respond of console process by using while loop like this:

while((str = br.readLine()) != null){
    retVal += str;
}

Here is the complete java function:

Read More!

Sunday, May 22, 2011

C++ Output String Manipulator


Manipulator                              Action
dec                               Set decimal conversion base format flag.
hex                               Set hexadecimal conversion base format flag.
oct                               Set octal conversion base format flag.
ws                                Extract whitespace characters.
endl                              Insert newline and flush stream.
ends                             Insert terminal null in string.
flush                             Flush an ostream.
setbase(int n)                Set conversion base format to base n (0, 8, 10, or 16). 0 means the default: decimal on output,                          ANSI C rules for literal integers on input.

resetiosflags(long f)       Clear the format bits specified by f.
setiosflags(long f)          Set the format bits specified by f.
setfill(int c)                    Set the fill character to c.
setprecision(int n)          Set the floating-point precision to n.
setw(int n)                     Set field width to n.


Sample Use:
int i = 36;
cout << dec << i << " " << hex << i << " " << oct << i << endl;
cout << dec;  // Must reset to use decimal base.
// displays 36 24 44


Read More!

Monday, May 16, 2011

VBnet Get Process List


'This A ConsoleApplication
Imports System.Diagnostics
Module Module1
    Sub Main()
        Dim proc() As Process = Process.GetProcesses()
        For Each p As Process In proc
            Try
                Console.Write(p.MainModule.FileName)
                If p.MainWindowTitle.Length > 0 Then
                    Console.WriteLine(" - " & p.MainWindowTitle)
                End If
            Catch ex As Exception
            End Try
        Next p
        Console.ReadKey()
    End Sub
End Module



Read More!

CSharp Get Process List

//This A ConsoleApplication
using System;
using System.Diagnostics; //manual using

class Program
{
    static void Main()
    {
        // Get List Of Running process
        Process [] proc = Process.GetProcesses();
        // Get one-by-one of process lists.
        foreach (Process p in proc)
        {
            try
            {
                Console.Write(p.MainModule.FileName.ToString());
                if (p.MainWindowTitle.Length > 0)
                Console.WriteLine(" - " + p.MainWindowTitle.ToString());
                else Console.WriteLine();
            }
            catch (Exception e){}
       }
        Console.ReadKey();
    }

Read More!

Sunday, May 15, 2011

VB.net - Get the name of enumerate color names



Module Module1
    'This example to calling back the name of declared enum
    ' Get the name of enumerate color names
    'sample by: Klampok_Child
    Sub Main()
        For Each color In [Enum].GetNames(GetType(ConsoleColor))
            Console.WriteLine(color)
            System.Threading.Thread.Sleep(200)
        Next
    End Sub
End Module

Read More!

Monday, May 02, 2011

VB.net Console with Form and Muti-threading


I using VS 2010, lets try it, Make your project with VB language, choose Console Application.
In Console Apllication, you can’t import the windows class (Imports System.Windows.Forms). Because, the references it not included automatically in Console Apllication project, but, it can be set, use this way:

·         On Solution Explorer, klik ‘My Project’ (Project properties and configurations):



·         Choose ‘Refferences’:

·         Click Add:

·         Select “System.Windows.Forms”:

“Click OK”, now you can create form in your console application :-), now you can use this import: Imports System.Windows.Forms.

NEXT: THE CODING

Import System.Windows.Forms in your project, and declaring this

    Dim T1 As New Threading.Thread(AddressOf Thread_one)
    Dim i As Integer = 0

Var I is use for counter, T1 is the thread class object, and Thread_One is the sub program that will run as thread T1.

Create the Main Sub:

    Sub Main()
        Console.WriteLine("Press enter and then the second thread will be run..")
        Console.ReadKey()
        T1.Start()
        Console.Write("Input User: ")
        Console.ReadLine()
        T1.Abort()
    End Sub

And this is the handler of Second Thread:

    Private Sub Thread_one()
        Dim Thread_one_form As New Form
        Dim Thread_one_label As New Label
        Dim i As Integer = 0
        Thread_one_form.Show()
        Thread_one_form.Top = 0
        Thread_one_form.Width = 200
        Thread_one_form.Height = 100
        Thread_one_label.Parent = Thread_one_form
        Thread_one_label.Dock = DockStyle.Top
        Thread_one_form.Text = "Waiting User Input"
        While True
            Thread_one_label.Text = i & " seconds."
            i += 1
            Threading.Thread.Sleep(1000)
            Thread_one_form.Left = (i + 1) * 10
            Thread_one_form.Update()
        End While
    End Sub

This subwill showing the form and wating for user input. U can edit this code for make your application run more better and escape from Not responding form process.

Download Tutorial (docx) and Project (VB2010)

Read More!

Thursday, April 28, 2011

CSharp Rounded Blinking Box in Console


Using VS2008 and written with CSharp Language, The rounded box will be blinking, use a simple timer handler you can try It, and this is the code:
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Kotak_Dekorasi k = new Kotak_Dekorasi();
            k.New(1, 1, 78, 5, 200);
           
        re:
           // j.Jalan();
            k.Jalan();
            Console.ReadKey();
            k.Berhenti();
            //j.Berhenti();
            Console.ReadKey();
            goto re;
        }
    }
    class Kotak_Dekorasi
    {
        TimerCallback TmH;
        public Timer tm;
        static char c1 = '*', c2 = ' ';
        static int x1, y1, x2, y2, d;
          public void New(int xx1, int yy1, int xx2, int yy2, int delay)
        {
            x1 = xx1; x2 = xx2; y1 = yy1; y2 = yy2; d = delay;
        }
          public void Jalan()
          {
              TmH = new TimerCallback(kedip);
              tm = new Timer(TmH, 0, 0, 300);

          }
          public void Berhenti()
          {
              tm.Dispose();
          }
        static void kedip(object kondisi) //TImer Handler bro..,
        {
            int i,j;
             Console.ForegroundColor = ConsoleColor.Green;
            //Atas-Bawah
           for (i = x1; i <= x2; i++)
            {
                Console.SetCursorPosition(i, y1);
                lip(i);
                Console.SetCursorPosition(i, y2);
                lip(i + (y2 - y1));
            }
            //Kanan-Kiri
            for (j = y1; j <= y2; j++)
            {
                Console.SetCursorPosition(x2, j) ;
                lip((x2-x1) + j);
                Console.SetCursorPosition(x1, j);
                lip(j);
            }

            char x =c1;c1 = c2; c2 = x;
        }

        static  void lip(int i)
        {
            if (i % 2 == 0)
                Console.Write(c1);
            else Console.Write(c2);
        }

    }
}

Read More!