[Tutor] Cmd Advice

Dave Hanson dave at hansonforensics.co.uk
Sat Feb 11 13:53:48 CET 2012

On Sat, Feb 11, 2012 at 12:43 PM, Dave Angel <d at davea.name> wrote:

> On 02/11/2012 07:14 AM, Dave Angel wrote:
>> On 02/11/2012 06:46 AM, Dave Hanson wrote:
>>> On Sat, Feb 11, 2012 at 11:35 AM, Dave Angel<d at davea.name>  wrote:
>>>  (Please don't top-post.  Please put your comments after whatever parts
>>>> you're quoting (replying to) )
>>>>  Apologies Dave.
>>>  You need to learn how to create a DOS window (or cmd window, just
>>>> another
>>>> name for same thing) in Windows.  One way is to use the RUN prompt in
>>>> the
>>>> Start menu, and run the program  CMD.  Another is to go to the Start
>>>> Menu->Accessories->DOS box.  it's been a long time since I ran Windows,
>>>> so
>>>> it may have some different name, but it should be in your accessories
>>>> somewhere.  Since I use such a shell constantly, I created a shortcut
>>>> key
>>>> to open one.
>>>> Once you do that, you should see a "box" with a C: prompt.  It is indeed
>>>> black, but you can customize it in many ways.  From there you can type
>>>> all
>>>> the commands that Walter was telling you about.  And it normally won't
>>>> go
>>>> away when a program finishes running, so you don't have the "black and
>>>> appears for a millisecond" syndrome.
>>>> Windows will create one of these if you run console things from the GUI,
>>>> but it also destroys them as soon as the program ends.
>>>> --
>>>> DaveA
>>>>  I did mention very early on in my query that I had restricted access to
>>> the Dos CMD prompt, hence why I asked if anyone knew how to create a self
>>> contained prompt within the Python program. I was under the impression
>>> that
>>> the .bat file Walter described would fill that gap.
>>> Thanks for your comments too, but your solution unfortunately is not one
>>> I
>>> can use as I cannot do all the usual methods to run the Dos prompt, .bat
>>> files are not a problem, I have used several in the past. My issue is
>>> that
>>> I cannot give commands directly to the Dos prompt and in turn not
>>> "operate"
>>> the python program as I can on my Ubuntu machine.
>> You still don't say "why" you can't get a traditional DOS prompt.  If
>> your Windows is somehow constrained (e.g. company rules) or broken (e.g.
>> somebody deleted some of the dll's in Windows/system32), then it's unclear
>> how we're supposed to guess just which things are going to work in it.
>>  it's also unclear whether it's the programmer's machine (yours) that's
>> constrained or only the end user.
>> In Windows, whenever a console program is launched without a console, one
>> is created for that program.  It goes away when the program ends, so it's
>> not real useful for learning and experimentation.  However, it does last as
>> long as the program does, so you can just use raw_input to  print your
>> "prompt" and accept commands.  Just remember you may want to add another
>> one at the end so the user gets a chance to read the last stuff you printed.
>> CMD is the cononical way to launch such a window, and batch files use CMD
>> by default.  So a batch file is one back-door.  But you can write your own
>> shell in any programming language you like, and if don't mark it as a GUI
>> app, it'll get a DOS box as well.  You can launch programs, including
>> Python programs, from your own shell.  And they'll normally continue to use
>> the same shell as your launcher.
>> Perhaps you didn't realize that CMD takes some command switches of its
>> own.  One of them tells it to stick around even when the current batch file
>> ends.
>> Random thoughts for an incompletely specified set of constraints.
>>  My apologies.  You gave lots more detail earlier in the thread, but I
> didn't make the connection till just now.  I only saw the message from
> Walter and your response and thought I could help.
> Some tests. Try a batch file with a PAUSE in it.  Do you get to hit enter
> at that point?  If that works, then try making a batch file that runs
> CMD.EXE.  Again, put a PAUSE at the end of the batch file so you can see
> any errors you might get.
> If those don't pan out, write a simple python program that does
> raw_input() in a loop (or input(), if you're on Python 3.x), and does
> something trivial with the stuff you type in.
>     while True
>         indata = raw_input("prompt:")
>         print indata
> It's not much harder to exec a program based on the contents of indata.
>  In Windows, you don't usually even have to separate out which part is the
> command, and which part is the parameters like -l
> When they eliminated cmd, they may have actually removed the file (or
> moved it to someplace inaccessible to your account), or they may have just
> eliminated the more obvious ways of running it.
> --
> DaveA
No worries Dave,

I did try with pause during my previous attempts to get the .bat file
running and when it ran with no errors I tried the pause again, pressed
Enter and the window just closes and nothing happens.

Cmd.exe does still exist, it's just that when you run it the message is
displayed saying I can't use it, I have a degree in computer forensics and
so know the registry key to remove the restricted access, this only lasts
until a reboot occurs then I have to do it again - and if I'm honest it's
not very professional of me to be 'buggering about' with my work machine's

If I understand your proposed 'loop' method correctly, could I use that to
pass commands to my "t" program then do you think? or have the loop built
into the "t.py" script?

Have to nip out, so I'll have to respond tomorrow now.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120211/200b6618/attachment.html>

More information about the Tutor mailing list