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

The name of the pictureThe name of the pictureThe name of the pictureClash 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










share|improve this question





















  • 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














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










share|improve this question





















  • 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












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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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






share|improve this answer




















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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






share|improve this answer




















  • 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














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






share|improve this answer




















  • 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












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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

GRUB: Fatal! inconsistent data read from (0x84) 0+xxxxxx

What makes Checkinstall packages not suitable for distribution?

Running the scala interactive shell from the command line