How to get program to output a command to the ubuntu command line just as if i had typed it

Clash Royale CLAN TAG#URR8PPP up vote
0
down vote
favorite
I have a program dbot that works in the ubuntu command line. If from its directory called dbot I type into the command line from my keyboard " ./dbot.sh any command " it works and does what i want.
So this works ~/dbot$ ./dbot.sh anycommand
I am a beginner and have written a python 3 program tragic.py that is in the same directory called dbot.
If from the ubuntu command line I run tragic.py in the background by ~/dbot$ python3 tragic.py & then if I copy and paste ./dbot.sh anycommand then it works and dbot does what i want. It has to be in the background or the command will not work when pasted so I am using &.
However I want my python program tragic.py to print out onto the command line ./dbot.sh anycommand so that the command gets issued to dbot just as if I had typed it or pasted it. However it does not work either in the background or foreground.
I have tried using a normal print statement and sys.stdout.write() both with and with out sys.stdout.flush() but with no luck
How can I get dbot to respond to the command printed by tragic.py in the ubuntu command line. I dont understand why when I type it or paste it then it works but not when tragic.py prints it or outputs it with sys.stdout.write
command-line python
add a comment |Â
up vote
0
down vote
favorite
I have a program dbot that works in the ubuntu command line. If from its directory called dbot I type into the command line from my keyboard " ./dbot.sh any command " it works and does what i want.
So this works ~/dbot$ ./dbot.sh anycommand
I am a beginner and have written a python 3 program tragic.py that is in the same directory called dbot.
If from the ubuntu command line I run tragic.py in the background by ~/dbot$ python3 tragic.py & then if I copy and paste ./dbot.sh anycommand then it works and dbot does what i want. It has to be in the background or the command will not work when pasted so I am using &.
However I want my python program tragic.py to print out onto the command line ./dbot.sh anycommand so that the command gets issued to dbot just as if I had typed it or pasted it. However it does not work either in the background or foreground.
I have tried using a normal print statement and sys.stdout.write() both with and with out sys.stdout.flush() but with no luck
How can I get dbot to respond to the command printed by tragic.py in the ubuntu command line. I dont understand why when I type it or paste it then it works but not when tragic.py prints it or outputs it with sys.stdout.write
command-line python
Some options for accomplishing this with various tools are discussed here.
â John1024
Mar 18 at 4:06
Are you talking about Command Substitution? As in./dbot.sh $(python3 tragic.py)?
â PerlDuck
Mar 18 at 10:28
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a program dbot that works in the ubuntu command line. If from its directory called dbot I type into the command line from my keyboard " ./dbot.sh any command " it works and does what i want.
So this works ~/dbot$ ./dbot.sh anycommand
I am a beginner and have written a python 3 program tragic.py that is in the same directory called dbot.
If from the ubuntu command line I run tragic.py in the background by ~/dbot$ python3 tragic.py & then if I copy and paste ./dbot.sh anycommand then it works and dbot does what i want. It has to be in the background or the command will not work when pasted so I am using &.
However I want my python program tragic.py to print out onto the command line ./dbot.sh anycommand so that the command gets issued to dbot just as if I had typed it or pasted it. However it does not work either in the background or foreground.
I have tried using a normal print statement and sys.stdout.write() both with and with out sys.stdout.flush() but with no luck
How can I get dbot to respond to the command printed by tragic.py in the ubuntu command line. I dont understand why when I type it or paste it then it works but not when tragic.py prints it or outputs it with sys.stdout.write
command-line python
I have a program dbot that works in the ubuntu command line. If from its directory called dbot I type into the command line from my keyboard " ./dbot.sh any command " it works and does what i want.
So this works ~/dbot$ ./dbot.sh anycommand
I am a beginner and have written a python 3 program tragic.py that is in the same directory called dbot.
If from the ubuntu command line I run tragic.py in the background by ~/dbot$ python3 tragic.py & then if I copy and paste ./dbot.sh anycommand then it works and dbot does what i want. It has to be in the background or the command will not work when pasted so I am using &.
However I want my python program tragic.py to print out onto the command line ./dbot.sh anycommand so that the command gets issued to dbot just as if I had typed it or pasted it. However it does not work either in the background or foreground.
I have tried using a normal print statement and sys.stdout.write() both with and with out sys.stdout.flush() but with no luck
How can I get dbot to respond to the command printed by tragic.py in the ubuntu command line. I dont understand why when I type it or paste it then it works but not when tragic.py prints it or outputs it with sys.stdout.write
command-line python
command-line python
asked Mar 18 at 2:03
ethertec
31
31
Some options for accomplishing this with various tools are discussed here.
â John1024
Mar 18 at 4:06
Are you talking about Command Substitution? As in./dbot.sh $(python3 tragic.py)?
â PerlDuck
Mar 18 at 10:28
add a comment |Â
Some options for accomplishing this with various tools are discussed here.
â John1024
Mar 18 at 4:06
Are you talking about Command Substitution? As in./dbot.sh $(python3 tragic.py)?
â PerlDuck
Mar 18 at 10:28
Some options for accomplishing this with various tools are discussed here.
â John1024
Mar 18 at 4:06
Some options for accomplishing this with various tools are discussed here.
â John1024
Mar 18 at 4:06
Are you talking about Command Substitution? As in
./dbot.sh $(python3 tragic.py)?â PerlDuck
Mar 18 at 10:28
Are you talking about Command Substitution? As in
./dbot.sh $(python3 tragic.py)?â PerlDuck
Mar 18 at 10:28
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can always use xargs, i.e.,
echo '-l' | xargs ls
will effectively execute ls -l. So in your case it should something like ./tragic.py | xargs ./dbot.sh, i.e., output of ./tragic.py command will be used as argument of ./dbot.sh
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can always use xargs, i.e.,
echo '-l' | xargs ls
will effectively execute ls -l. So in your case it should something like ./tragic.py | xargs ./dbot.sh, i.e., output of ./tragic.py command will be used as argument of ./dbot.sh
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
add a comment |Â
up vote
0
down vote
accepted
You can always use xargs, i.e.,
echo '-l' | xargs ls
will effectively execute ls -l. So in your case it should something like ./tragic.py | xargs ./dbot.sh, i.e., output of ./tragic.py command will be used as argument of ./dbot.sh
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can always use xargs, i.e.,
echo '-l' | xargs ls
will effectively execute ls -l. So in your case it should something like ./tragic.py | xargs ./dbot.sh, i.e., output of ./tragic.py command will be used as argument of ./dbot.sh
You can always use xargs, i.e.,
echo '-l' | xargs ls
will effectively execute ls -l. So in your case it should something like ./tragic.py | xargs ./dbot.sh, i.e., output of ./tragic.py command will be used as argument of ./dbot.sh
answered Mar 18 at 5:57
Jacek Herbrych
1716
1716
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
add a comment |Â
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
Thanks for your help Jacek Herbrych - that is what i am looking for. I will give it a try! and thanks to John1024 and PerlDuck too.
â ethertec
Mar 18 at 17:43
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1016891%2fhow-to-get-program-to-output-a-command-to-the-ubuntu-command-line-just-as-if-i-h%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Some options for accomplishing this with various tools are discussed here.
â John1024
Mar 18 at 4:06
Are you talking about Command Substitution? As in
./dbot.sh $(python3 tragic.py)?â PerlDuck
Mar 18 at 10:28