Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 835 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how may i do to using bash scripting inside a python project?

#1
hi
i want to learn about how may i do an application in python that read, write and even do some functions by calling bash commands in linux

imagine this:

an app that allows you to put a value, then run a command with that value as a "-" variable, so you can do something like


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


but... by choosing or writing the freq value using a gui or even options in a command-line python script.

something like "processor.py -freq 1"
Reply

#2
With read write I supposed you mean reading/writing files? There's a method in python called open.

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.



To run a command in Python you could use the subprocess module

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

or the os module

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


About being able to pass them as arguments to the python script itself you've got a lot of options. The simplest is to use the sys module and optionally parse the arguments yourself depending on how advanced you want it. Here's an example of a script that prints the first argument that you pass to the script, basically an echo script, but we set it as a positional argument and force it to be passed.

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

But as I mentioned above you'd need to parse it yourself if you want to have options starting with "-". In this case it'd be simpler to use the argparse module where you can choose what options you want and what values they need to be( int, string ) or if they're just boolean options. A basic google search would've gotten you all the answers - suggestion would be to do a trial and error and just test your way forward until you get the basic understanding of how things work, get familiar with the modules( os, sys ).

If you want to have a gui you'd need to use a library like tkinter, Qt, Gtk+, Kivy etc.
Reply

#3
Quote:(11-21-2019, 01:07 AM)obnoxious Wrote:

[To see links please register here]

With read write I supposed you mean reading/writing files? There's a method in python called open.

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.



To run a command in Python you could use the subprocess module

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

or the os module

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


About being able to pass them as arguments to the python script itself you've got a lot of options. The simplest is to use the sys module and optionally parse the arguments yourself depending on how advanced you want it. Here's an example of a script that prints the first argument that you pass to the script, basically an echo script, but we set it as a positional argument and force it to be passed.

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

But as I mentioned above you'd need to parse it yourself if you want to have options starting with "-". In this case it'd be simpler to use the argparse module where you can choose what options you want and what values they need to be( int, string ) or if they're just boolean options. A basic google search would've gotten you all the answers - suggestion would be to do a trial and error and just test your way forward until you get the basic understanding of how things work, get familiar with the modules( os, sys ).

If you want to have a gui you'd need to use a library like tkinter, Qt, Gtk+, Kivy etc.

thank you so much for your help!
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through