블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-25 09:56

최근 명령프롬프트를 이용해서 몇몇 작업을 하다보니 GUID 등을 텍스트 파일에 옮기고 복사하는 법에 대해서 몇몇 분들이 질문하셔서 간단한 내용 포스팅합니다.  저도 기초적인 것만 아는지라 자세한 내용은 고수님들의 도움을 ^^;;;;

 우선 살짝 개념부터 말씀드리자면 명령프롬프트에서 보이는 화면을 텍스트 파일로 출력하는 것처럼 입력과 출력사이의 개체를 변경하는 것을 리다이렉션(Redirection)이라고 합니다.  일반적으로 리다이렉션으로 많이 활용하는 것이 명령프롬프트에서 자신이 출력하고자 하는 내용을 텍스트 파일 등으로 보이게 하는거죠.  물론 예전에 포스팅했던 복사/붙여넣기 등의 방법을 활용할 수도 있지만 몇 글자 안되는 명령어 입력으로 이를 바로 해결할 수 있습니다.  이제 그렇게 출력할 수 있는 몇가지 방법을 알려드릴게요.

◈  ">" 와 ">>" 사용하기
   

예 : bcdedit > liverex.txt
      dir/w >> liverex.txt
 

 위에서 말한 > 와 >> 의 차이를 위에서 예로 든 명령어를 기준으로 설명드릴게요
 ">"는 liverex.txt 라는 이미 같은 이름의 파일이 있다면 덮어쓰고, 없다면 새로 텍스트파일을 생성하여 출력되는 내용을 텍스트 파일에 저장하는 것입니다.  
 그리고 ">>"는 liverex.txt 라는 텍스트파일을 생성하는데 혹시 같은 파일이 있다면 기존에 존재하던 내용의 아래에 덧붙여 저장되는 것입니다.  물론 없다면 새로 생성하는 것이구요.  생성되는 파일을 명령프롬프트에서의 명령어 작성시 경로에 있습니다.  어떻게 표현되는지는 아래의 영상을 참고하세요~ 영상으로 하는게 확실히 이해되실 듯 해서ㅎㅎ




◈  "|"(Shift+\) 와 "&" 사용하기

예 : bcdedit > liverex.txt | start notepad liverex.txt
      dir/w >> liverex.txt & notepd liverex.txt


 위에서 단순히 > 와 >> 를 이용했을 때는 본인이 직접 txt 파일을 열어야 결과를 확인할 수 있었습니다.  하지만 이번에 말씀드리는 "|" 와 "&" 는 바로 텍스트파일이 열리면서 결과를 보여주게 됩니다.  역시 아래 영상을 참고하시면 쉽게 이해되시겠네요.



 이제 리다이렉션(Redirection)을 활용해서 더 편하게 작업(?)하세요 ^^



출처 : http://liverex.tistory.com/121

반응형
Posted by blueasa
, |

보통 Windows 환경에서 환경변수를 등록하는방법은 누구나 알다시피 
아래와 같이 시스템 속성에서 찾을수 있습니다.




하지만 command 창으로 지정하는 방법이 있습니다.
실행
 - cmd
 

>path

현재 환경변수 정보 보여줌.

 

>set path

path명령과 동일한 현재 환경변수 정보와 동일한 path 정보와
pathext라는 시스템 실행파일 확장자 변수가 같이 나온다.

 

>set path =%path%;추가하고자하는경로;

ex) >set path=%path%;c:\java\bin;

환경변수 추가(일시적)

 

>setx path "%PATH%;추가하고자하는경로"

ex) >setx path "%PATH%;c:\java\bin"

환경변수 추가(영구적)

 
%path%를 하는 이유는 현재 환경변수에 path 정보를 가져와서 
현재 환경변수에 새로운 환경변수를 추가해야하기 때문입니다.


echo 명령어를 사용하면 %%를 이용하여 모든 환경변수 내용을 알아낼수 있습니다.
ex) echo %os%


출처  참고

http://blog.naver.com/timberx?Redirect=Log&logNo=



출처 : http://visu4l.tistory.com/391

반응형
Posted by blueasa
, |

윈도우를 종료
System.Diagnostics.Process.Start("cmd.exe","ShutDown.exe -s -f -t 00");


윈도우를 재부팅

System.Diagnostics.Process.Start("cmd.exe","ShutDown.exe -r -f -t 00");

 

특정 폴더 열기
System.Diagnostics.Process.Start("explorer.exe", "C:\Temp");

특정 사이트 열기
System.Diagnostics.Process.Start("explorer.exe", "http://www.naver.com");

 

도스명령어 실행

System.Diagnostics.Process.Start("cmd.exe","/c dir");

// cmd 옵션에 대해 더 알고싶으면.. c:>help cmd

 

Process.Start 메서드 사용형식
 

using System.Diagnostics;

//System.Diagnostics 네임스페이스는 시스템 프로세스, 이벤트 로그 및 성능 카운터와 상호 작용할 수 있는 클래스를 제공합니다.

 

public bool Start();
//이 Process 구성 요소의 StartInfo 속성으로 지정된 프로세스 리소스를 시작하거나 다시 사용하여 구성 요소에 연결합니다.

 

Process myProcess = new Process();
string myDocumentsPath =   Environment.GetFolderPath(Environment.SpecialFolder.Personal);
myProcess.StartInfo.FileName = myDocumentsPath + "
\MyFile.doc"; 
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();

 

public static Process Start( ProcessStartInfo startInfo);
// ProcessStartInfo : 파일 이름 및 모든 명령줄 인수를 포함하여 프로세스를 시작하는 데 사용되는 정보
// 시작할 프로세스의 파일 이름 같은 프로세스 시작 정보가 포함된 매개 변수에 의해 지정된 
// 프로세스 리소스를 시작하고 해당 리소스를 새 Process 구성 요소에 연결합니다

 

ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
startInfo.Arguments = "
www.naver.com";
Process.Start(startInfo);

 

public static Process Start(string fileName);
// fileName : 프로세스에서 실행될 응용 프로그램 파일 이름입니다.

//문서 또는 응용 프로그램 파일 이름을 지정하여 프로세스 리소스를 시작하고 해당 리소스를 새 Process 구성 요소에 연결합니다

 

Process.Start("IExplore.exe");

 

public static Process Start(string fileName, string arguments); 
// arguments : 프로세스를 시작할 때 전달할 명령줄 인수입니다

//응용 프로그램 이름 및 명령줄 인수 집합을 지정하여 프로세스 리소스를 시작하고 해당 리소스를 새 Process 구성 요소에 연결합니다.

 

Process.Start("IExplore.exe", "C:\myPath\myFile.htm");
Process.Start("IExplore.exe", "C:\myPath\myFile.asp");

 

 

Process 클래스

Process 구성 요소는 컴퓨터에서 실행 중인 프로세스에 대한 액세스를 제공합니다. 간단히 말해 프로세스란 실행 중인 응용 프로그램을 말합니다.

 

Process 구성 요소는 응용 프로그램의 시작, 중지, 제어 및 모니터링을 위한 유용한 도구입니다.
Process 구성 요소를 사용하면 실행 중인 프로세스의 목록을 얻거나 새로운 프로세스를 시작할 수 있습니다. 또한 Process 구성 요소를 사용하여 시스템 프로세스에도 액세스할 수 있습니다. 
Process 구성 요소를 초기화한 후에는 해당 구성 요소를 사용하여 실행 중인 프로세스에 대한 정보를 얻을 수 있으며 그러한 정보에는 스레드 집합, 로드된 모듈(.dll 및 .exe 파일), 프로세스가 사용하고 있는 메모리 양과 같은 성능 정보 등이 포함됩니다.

 

프로세스 구성 요소는 속성 그룹에 대한 정보를 한 번에 가져옵니다. Process 구성 요소가 특정 그룹의 한 멤버에 대한 정보를 가져올 때 해당 그룹의 나머지 속성 값이 캐싱되므로 Refresh 메서드를 호출하지 않는 한 그룹의 다른 멤버에 대한 새로운 정보를 가져오지 않습니다. 따라서 속성 값이 Refresh 메서드를 마지막으로 호출하여 얻은 속성 값과 같을 수 있습니다. 이러한 그룹 명세는 운영 체제에 따라 다릅니다.

 

더 자세한 사항은 Microsoft Visual Studio .NET 2003 도움말에서 Process 클래스를 참고하세요.

 

 

도스명령수행 프로그램 


 

[전체소스]


using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Diagnostics;

using System.IO;

using System.Threading;


namespace mouseEvents

{


    public class Form1 : System.Windows.Forms.Form

    {

        private System.Windows.Forms.TextBox textBox1;

        private System.Windows.Forms.Label label2;

        private System.ComponentModel.IContainer components;

        private System.Windows.Forms.TextBox tbComm;

        private System.Windows.Forms.Button btnExec;



        public Form1()

        {

            InitializeComponent();

        }


        protected override void Dispose( bool disposing )

        {

            if( disposing )

            {

                if (components != null)

                {

                    components.Dispose();

                }

            }

            base.Dispose( disposing );

        }


        #region Windows Form Designer generated code

        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

        {

            this.label2 = new System.Windows.Forms.Label();

            this.tbComm = new System.Windows.Forms.TextBox();

            this.btnExec = new System.Windows.Forms.Button();

            this.textBox1 = new System.Windows.Forms.TextBox();

            this.SuspendLayout();

            //

            // label2

            //

            this.label2.Location = new System.Drawing.Point(8, 8);

            this.label2.Name = "label2";

            this.label2.Size = new System.Drawing.Size(72, 17);

            this.label2.TabIndex = 5;

            this.label2.Text = "도스명령어:";

            //

            // tbComm

            //

            this.tbComm.Location = new System.Drawing.Point(80, 8);

            this.tbComm.Name = "tbComm";

            this.tbComm.Size = new System.Drawing.Size(355, 21);

            this.tbComm.TabIndex = 6;

            this.tbComm.Text = "";

            //

            // btnExec

            //

            this.btnExec.Location = new System.Drawing.Point(440, 8);

            this.btnExec.Name = "btnExec";

            this.btnExec.Size = new System.Drawing.Size(104, 25);

            this.btnExec.TabIndex = 1;

            this.btnExec.Text = "실행";

            this.btnExec.Click += new System.EventHandler(this.button2_Click);

            //

            // textBox1

            //

            this.textBox1.AcceptsReturn = true;

            this.textBox1.AcceptsTab = true;

            this.textBox1.Location = new System.Drawing.Point(8, 32);

            this.textBox1.Multiline = true;

            this.textBox1.Name = "textBox1";

            this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;

            this.textBox1.Size = new System.Drawing.Size(528, 312);

            this.textBox1.TabIndex = 2;

            this.textBox1.Text = "";

            //

            // Form1

            //

            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

            this.ClientSize = new System.Drawing.Size(547, 350);

            this.Controls.Add(this.tbComm);

            this.Controls.Add(this.label2);

            this.Controls.Add(this.textBox1);

            this.Controls.Add(this.btnExec);

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

            this.MaximizeBox = false;

            this.Name = "Form1";

            this.Text = "Process Class";

            this.ResumeLayout(false);


        }

        #endregion


        [STAThread]

        static void Main()

        {

            Application.Run(new Form1());

        }


        private void button2_Click(object sender, System.EventArgs e)

        {

            this.start();

        }


        private void start()

        {


            //Network 변수

            StreamWriter DosWriter;

            StreamReader DosRedaer;

            StreamReader ErrorReader;

           

            //프로세스 생성및 초기화

            Process DosPr = new Process();

           

            ProcessStartInfo psI = new ProcessStartInfo("cmd");

            psI.UseShellExecute = false;

            psI.RedirectStandardInput = true;

            psI.RedirectStandardOutput = true;

            psI.RedirectStandardError = true;

            psI.CreateNoWindow = true;



            //명령 실행

            DosPr.StartInfo = psI;

            DosPr.Start();

            DosWriter = DosPr.StandardInput;

            DosRedaer = DosPr.StandardOutput;

            ErrorReader = DosPr.StandardError;


            DosWriter.AutoFlush = true;


            DosWriter.WriteLine(tbComm.Text);

           

            DosWriter.Close();


            //출력

            textBox1.Text = DosRedaer.ReadToEnd();

            textBox1.Text += ErrorReader.ReadToEnd();


        }

    }

}



  작성자 : HOONS(박경훈)
  이메일 : tajopkh@hanmail.net

출처 : http://www.cyworld.com/nowy/192742


[출처 : http://skql.tistory.com/510]

반응형
Posted by blueasa
, |