Python Forum
Write something to another script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write something to another script
#1
I just want to write something to another script like this example; When i write msfconsole to terminal is going to opening metasploit so i can do this with os.system() code too , but when metasploit is working can still run my codes?
Huh Angel
Reply
#2
I assume if you use the subprocess module, and pipe output into the program's stdin, it'd work how you'd expect. But I'm not entirely sure what you're asking, so that's just a guess.

Could you maybe write some pseudocode, showing what you'd want to happen?
Reply
#3
@nilamo of course man thanks for reply.


Quote:x = input("exploit name.:")
os.system("msfconsole")
os.system(x)
OUT: ============================
OUT: METASPLOIT
OUT: logos etc.
OUT:
OUT: ============================
in: x (i want to write my own codes to here but i can't write because my codes end of after os.system("msfconsole") code)
Reply
#4
I don't think you want to be using os.system(). That's alright if what you're doing is running a command, and you don't really care what the output of that command is, or you don't want to interact with it.

You do want to interact with it. So I think you should try the subprocess module: https://docs.python.org/3/library/subprocess.html

Using stdin=PIPE and stdout=PIPE, you can communicate with the external process and send commands to it.

You can also look into the pexpect module, though that isn't built into python. https://pexpect.readthedocs.io/en/stable/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is this possible to write a script for checking data from website? WanW 2 1,115 Jun-02-2022, 02:31 AM
Last Post: Larz60+
  Is it possible to write a python script to block twitter feeds? cubangt 0 866 Apr-07-2022, 04:14 PM
Last Post: cubangt
  Trying to write and execute first Python script garvind25 3 2,890 May-23-2020, 07:36 PM
Last Post: garvind25
  How to write a script to execute a program need passing additional input? larkypython 2 2,522 Nov-23-2019, 04:38 AM
Last Post: larkypython
  Python Script Spawned by Cron or Systemd doesn't write files..? johnnyrobot 2 2,576 May-24-2019, 07:04 PM
Last Post: Larz60+
  Script to read, write data to excel file and update it to firebase Expertlearner 1 3,485 Jan-03-2018, 03:32 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020