Is there a replacement of linux's "command &" in windows?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • walsug
    New Member
    • Oct 2008
    • 14

    Is there a replacement of linux's "command &" in windows?

    hello,
    I know in linux the "&" right after a command line is used to put the execution of this command into the background.
    The question is :Is there a substitution for this under the windows os?
    thx~
    -yogo
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Maybe the "start <command>" command can be of any use.

    kind regards,

    Jos

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Moved to the Windows forum

      Comment

      • AmberJain
        Recognized Expert Contributor
        • Jan 2008
        • 922

        #4
        Hello,

        As Sir JosAh said, "start" command will help you out. Although if you want to run execution of command in background, then the exact syntax would be:

        Code:
        start /MIN edit
        This will open a separate MS DOS editor window in background. (more information here).

        NOTE- Thanks sir JosAH, I never knew that 'start' command exists inside Windows OSes. I just googled and found more about it. And so I would like to Thank you.

        Thanks......
        AmbrNewlearner

        Comment

        • walsug
          New Member
          • Oct 2008
          • 14

          #5
          Originally posted by ambrnewlearner
          Hello,

          As Sir JosAh said, "start" command will help you out. Although if you want to run execution of command in background, then the exact syntax would be:

          Code:
          start /MIN edit
          This will open a separate MS DOS editor window in background. (more information here).

          NOTE- Thanks sir JosAH, I never knew that 'start' command exists inside Windows OSes. I just googled and found more about it. And so I would like to Thank you.

          Thanks......
          AmbrNewlearner
          hello,
          I 've tried start command and yes it works! thank you!
          but a little bit different form the code you posted:
          Code:
          start /B edit
          /B create no windows but /MIN minimized the new window,the former is what I want :),thank sir JosAH offer such a good hint~
          but here comes about another problem,I'm gonna to use "start" like this:
          Code:
          start /B -MyOwnCommand-
          but my command would probably output to the stdout or stderr,I want to restrict this output,just like the linux's ">/dev/null 2>&1",the "echo off" doesn't work,then what could I do?

          Comment

          • walsug
            New Member
            • Oct 2008
            • 14

            #6
            Originally posted by Banfa
            Moved to the Windows forum
            sorry for the misposting
            I'll be attentive next time

            -yogo

            Comment

            • AmberJain
              Recognized Expert Contributor
              • Jan 2008
              • 922

              #7
              Originally posted by walsug
              /B create no windows but /MIN minimized the new window,the former is what I want :)
              Well, I thought that you said to run the command in background..... .
              BTW, no problems....... .......

              Originally posted by walsug
              but here comes about another problem,I'm gonna to use "start" like this:
              Code:
              start /B -MyOwnCommand-
              but my command would probably output to the stdout or stderr,I want to restrict this output,just like the linux's ">/dev/null 2>&1",the "echo off" doesn't work,then what could I do?
              You can instead use redirection.
              By using redirection (< or >) you can direct output/input from/to a program to a specific file or device. More information here. You can also search google for elaborated information about the same.


              Hope this helps.......... .
              AmbrNewlearner

              Comment

              • walsug
                New Member
                • Oct 2008
                • 14

                #8
                Originally posted by ambrnewlearner
                Well, I thought that you said to run the command in background..... .
                BTW, no problems....... .......


                You can instead use redirection.
                By using redirection (< or >) you can direct output/input from/to a program to a specific file or device. More information here. You can also search google for elaborated information about the same.


                Hope this helps.......... .
                AmbrNewlearner
                hi,
                I've hit this page and got some useful info,I knew the pipe "|" and redirection ">"or ">>",I don't want the application to generate extra file,so i do it as follows:
                create a console application with an empty main(),which is named "null.exe" and placed in the same path as my application,the n run my application like this:
                Code:
                start /B -myapp- 2>&1|null
                to throw both stdout and stderr into a null operation.
                To improve this,I have to replace the null.exe with an existing command that almost do nothing in this context.Then the booting command may be like this:
                Code:
                start /B -myapp- 2>&1 | cd .
                which could also do the work above.

                thanks for your hints
                -yogo

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  Originally posted by walsug
                  I don't want the application to generate extra file,so i do it as follows:
                  create a console application with an empty main(),which is named "null.exe" and placed in the same path as my application,the n run my application like this:
                  Code:
                  start /B -myapp- 2>&1|null
                  to throw both stdout and stderr into a null operation.
                  You don't need to create an application (null.exe), there is a null device (called nul) that you can pipe output to when you don't want it

                  Code:
                  start /B -myapp- 2>&1|nul

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    @ECHO OFF
                    and
                    @ECHO ON
                    simply control whether or not the commands themselves are echoed to the screen. They have no bearing as to what is displayed from within the program itself.

                    As Banfa said, the Nul device is used to consign the general output (not errors) to the bit-bucket.
                    Code:
                    start /B -myapp- 2>nul
                    The absence of the /WAIT parameter to START is what allows it to run asynchronously. /B ensures it executes without creating a new window.

                    Comment

                    • walsug
                      New Member
                      • Oct 2008
                      • 14

                      #11
                      hi,
                      I tested the "|nul" that Sir.Banfa offered,but here popup a msgbox says:"指定されたデバイス 、パス、またはファイルにアクセ スできません。アクセス許可がな い可能性があります 。"Then console says:"アクセスが拒否され ました。"Both mean "access denied!Maybe you have no access right to this device",then what could I probably do?
                      -yogo

                      Comment

                      • walsug
                        New Member
                        • Oct 2008
                        • 14

                        #12
                        Originally posted by NeoPa
                        @ECHO OFF
                        and
                        @ECHO ON
                        simply control whether or not the commands themselves are echoed to the screen. They have no bearing as to what is displayed from within the program itself.

                        As Banfa said, the Nul device is used to consign the general output (not errors) to the bit-bucket.
                        Code:
                        start /B -myapp- 2>nul
                        The absence of the /WAIT parameter to START is what allows it to run asynchronously. /B ensures it executes without creating a new window.
                        Now I've made it clear,it's not allowed to pipe("|") to NUL,insteat,you have to redirect to it(">"or">>"),t he whole command line shall like this:
                        Code:
                        start /B -myapp- >nul 2>&1
                        Thanks to Banfa and Neopa,I've solved this problem,now I could perfectly replace the linux counterpart.
                        regards,
                        yogo.

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32633

                          #13
                          Indeed Yogo.

                          Redirecting and piping were added into DOS from Unix many years ago, even though it was already available in Unix well before DOS was even a twinkle in Microsoft's eye.

                          Essentially it was added to look like what was used in Unix, even though the implementation is fundamentally different (under the hood/bonnet). As some of the things that make it work the way it does are not available to DOS/Windows, I believe there are still some elements of it which are still not fully copied.

                          For most uses though, just copy Unix.

                          Comment

                          Working...