Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Oct 2008
Posts: 13
#1: Oct 22 '08
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's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Oct 22 '08

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


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

kind regards,

Jos
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,171
#3: Oct 22 '08

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


Moved to the Windows forum
ambrnewlearner's Avatar
Expert
 
Join Date: Jan 2008
Location: A city in my country ;)
Posts: 855
#4: Oct 22 '08

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


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:

Expand|Select|Wrap|Line Numbers
  1. 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
Newbie
 
Join Date: Oct 2008
Posts: 13
#5: Oct 23 '08

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


Quote:

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:

Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. 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?
Newbie
 
Join Date: Oct 2008
Posts: 13
#6: Oct 23 '08

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


Quote:

Originally Posted by Banfa

Moved to the Windows forum

sorry for the misposting
I'll be attentive next time

-yogo
ambrnewlearner's Avatar
Expert
 
Join Date: Jan 2008
Location: A city in my country ;)
Posts: 855
#7: Oct 23 '08

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


Quote:

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..............

Quote:

Originally Posted by walsug

but here comes about another problem,I'm gonna to use "start" like this:

Expand|Select|Wrap|Line Numbers
  1. 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
Newbie
 
Join Date: Oct 2008
Posts: 13
#8: Oct 24 '08

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


Quote:

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,then run my application like this:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. start /B -myapp- 2>&1 | cd .
which could also do the work above.

thanks for your hints
-yogo
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,171
#9: Oct 24 '08

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


Quote:

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,then run my application like this:

Expand|Select|Wrap|Line Numbers
  1. 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

Expand|Select|Wrap|Line Numbers
  1. start /B -myapp- 2>&1|nul
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#10: Oct 25 '08

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


@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.
Expand|Select|Wrap|Line Numbers
  1. 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.
Newbie
 
Join Date: Oct 2008
Posts: 13
#11: Oct 28 '08

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


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
Newbie
 
Join Date: Oct 2008
Posts: 13
#12: Oct 28 '08

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


Quote:

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.

Expand|Select|Wrap|Line Numbers
  1. 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">>"),the whole command line shall like this:
Expand|Select|Wrap|Line Numbers
  1. 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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#13: Oct 28 '08

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


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.
Reply