halis
Ekim 31, 2020, 5:42ös
1
Merhaba arkadaşlar. os modülünü kullanmadan (hatta hiçbir modülü kullanmadan) cmd ’ye komut göndermek istiyorum. Bu sadece aklıma takılan bir soru. Mesela os modülünün listdir()
metodunun bir benzerini yapmayı istiyorum. Bunun için cmd ye dir > file.txt
şeklinde bir komut gönderip çıktıyı file.txt’den almayı ve open()
fonksiyonuyla bir .bat dosyayı oluşturup içine yazmayı düşündüm ancak os modülü olmadan o .bat dosyasını nasıl çalıştırabilirim bulamadım. Biraz gereksiz bir iş olsa da aklıma takıldı, os modülünün arka planda nasıl çalıştığını kavramaya çalışıyorum şimdiden teşekkürler.
Öyleyse kaynak kodlarını okuyabilirsiniz.
r"""OS routines for NT or Posix depending on what system we're on.
This exports:
- all functions from posix or nt, e.g. unlink, stat, etc.
- os.path is either posixpath or ntpath
- os.name is either 'posix' or 'nt'
- os.curdir is a string representing the current directory (always '.')
- os.pardir is a string representing the parent directory (always '..')
- os.sep is the (or a most common) pathname separator ('/' or '\\')
- os.extsep is the extension separator (always '.')
- os.altsep is the alternate pathname separator (None or '/')
- os.pathsep is the component separator used in $PATH etc
- os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
- os.defpath is the default search path for executables
- os.devnull is the file path of the null device ('/dev/null', etc.)
Programs that import and use 'os' stand a better chance of being
portable between different platforms. Of course, they must then
only use functions that are defined by all platforms (e.g., unlink
and opendir), and leave all pathname manipulation to os.path
This file has been truncated. show original
/* POSIX module implementation */
/* This file is also used for Windows NT/MS-Win. In that case the
module actually calls itself 'nt', not 'posix', and a few
functions are either unimplemented or implemented differently. The source
assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
of the compiler used. Different compilers define their own feature
test macro, e.g. '_MSC_VER'. */
#include "Python.h"
#ifdef __VXWORKS__
# include "pycore_bitutils.h" // _Py_popcount32()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_ReInitThreads()
#include "pycore_fileutils.h" // _Py_closerange()
#include "pycore_import.h" // _PyImport_ReInitLock()
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
This file has been truncated. show original