littleguy1 Posted January 11, 2011 Posted January 11, 2011 Hey guys! I just got started with Teensy. I am currently working on a Windows Machine and I wanted to experiment with how Teensy works with the command prompt. I wanted to program teensy to type in commands, then receive the command prompt output. Does anyone know how I can do that? I really need help so I hope someone could answer my question? Thank you very much. SIncerely littleguy1 Quote
Sparda Posted January 11, 2011 Posted January 11, 2011 If the Teensy is acting as a keyboard... it can't receive output from the command prompt. What you could do though is have the Teensy write a script that contains all the logic necessary to handle what ever you want to do. Quote
littleguy1 Posted January 11, 2011 Author Posted January 11, 2011 Thank you for replying so quickly! I had what you suggested, have Teensy execute a script on the command line. I had Teensy open up the terminal. Then it types into the command prompt every possible drive name E:\Scripts>F: E:\Scripts>file or directory not found E:\Scripts>runscript.bat E:\Scripts>copy NUL hi.txt <- it executes the same script even though its not supposed to if the drive is not found. ... Then it executes a script. That was my way of finding the mounted sd card and execute the script. But, it ended up executing the same script 5 times since every time the drive letter changes and it doesn't exist, the command prompt would stay at that drive and execute the current script.... If there's a way for teensy to find out what drive Windows mounted the Sd card to execute the script....that would be great. littleguy1 Quote
Mr-Protocol Posted January 12, 2011 Posted January 12, 2011 You are confused. The teensy is not a smart device. It is a one way device if used via USB to do things on the computer. It is only a keyboard and mouse (HID - Human Interface Device). It does not get feedback/commands/logic back over USB. Quote
littleguy1 Posted January 12, 2011 Author Posted January 12, 2011 You are confused. The teensy is not a smart device. It is a one way device if used via USB to do things on the computer. It is only a keyboard and mouse (HID - Human Interface Device). It does not get feedback/commands/logic back over USB. Since Teensy is a one way device, I suppose the only thing is to have it run scripts then....:( But back to finding which drive the computer named the mounted SD Card, how would I code the .bat file so that I know where it is? For Mac, I could just go to /Volumes/MemoryCard/ but for windows, there are different drive letters... I do not want to ask you to code it for me, I just need some hints or examples so that I can figure it out myself. By the way, thank you for answering. :) Littleguy1 Quote
Mr-Protocol Posted January 12, 2011 Posted January 12, 2011 If my forensic class's material and brain serves me right, there are plenty of registry entries that define external devices. BTW, your accnt is littleguy1 and Gender says Female. Confused? :P Quote
littleguy1 Posted January 12, 2011 Author Posted January 12, 2011 If my forensic class's material and brain serves me right, there are plenty of registry entries that define external devices. BTW, your accnt is littleguy1 and Gender says Female. Confused? :P Hahaha Nah, I call my little Teensy the little guy :) I am a female, I find there's not a lot of females in these forums...but anyway, thanks for the suggestions. Um, what do you know about external devices? I have tried different commands to get the output but it doesn't lead me to anywhere. I did: fsutil fsinfo devices The command line returns: C: D: E: F: All the devices that are currently occupied on my computer. But then again, it doesn't tell me much about where the SD card is. Thanks, littleguy1 Quote
BITS1 Posted January 12, 2011 Posted January 12, 2011 Hey littleguy1, What you had the teensy do was to type out each Drive name consecutively and once it found it, it remained in the same drive. I can suggest that you could redirect the command line back to drive C: each time you try to 'cd' to the new drive. If you do that, it will allow the script to run once when Teensy finds the correct drive. Hope it helps. Keep up the effort. :) Sincerely, Bits1 Quote
PineDominator Posted January 13, 2011 Posted January 13, 2011 Since Teensy is a one way device, I suppose the only thing is to have it run scripts then....:( But back to finding which drive the computer named the mounted SD Card, how would I code the .bat file so that I know where it is? For Mac, I could just go to /Volumes/MemoryCard/ but for windows, there are different drive letters... I do not want to ask you to code it for me, I just need some hints or examples so that I can figure it out myself. By the way, thank you for answering. :) Littleguy1 Hi there Littleguy1 I just updated my code for automating dipswitches and there is also a library I made that has some functions to copy files from a drive to computer and computer to drive using it's volume label. the function that copy's from computer to external drive runs "cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \"" + volumeLabel + "\"') DO SET DLETTER=%G" you could do the same thing so something like "keyboard.print("%DLETTER%\\someFolder\\script.bat")" %DLETTER% is a variable that on my computer shows up like e: hope this helps http://code.google.com/p/arduino-switches-tfmanlib/downloads/list Quote
littleguy1 Posted January 13, 2011 Author Posted January 13, 2011 (edited) Hi there Littleguy1 I just updated my code for automating dipswitches and there is also a library I made that has some functions to copy files from a drive to computer and computer to drive using it's volume label. the function that copy's from computer to external drive runs "cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \"" + volumeLabel + "\"') DO SET DLETTER=%G" you could do the same thing so something like "keyboard.print("%DLETTER%\\someFolder\\script.bat")" %DLETTER% is a variable that on my computer shows up like e: hope this helps http://code.google.com/p/arduino-switches-tfmanlib/downloads/list Hi peterfm! Thanks a bunch for showing me the library you made. I think it's impressive. I will try to see if that will work for Teensy on Windows. :) Thanks again! littleguy1 Edited January 13, 2011 by littleguy1 Quote
xFiles Posted January 13, 2011 Posted January 13, 2011 Hey petertfm, I am trying that code out with the help of your library, but I don't understand where I put any of that. Do I directly paste the string cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \"" + volumeLabel + "\"') DO SET DLETTER=%G onto my command line? Or should I create a file 'cmd.exe' containing the line /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \"" + volumeLabel + "\"') DO SET DLETTER=%G Thanks for letting us use this xxx, xFiles Quote
PineDominator Posted January 14, 2011 Posted January 14, 2011 Hey petertfm, I am trying that code out with the help of your library, but I don't understand where I put any of that. Do I directly paste the string cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \"" + volumeLabel + "\"') DO SET DLETTER=%G onto my command line? Or should I create a file 'cmd.exe' containing the line /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \"" + volumeLabel + "\"') DO SET DLETTER=%G Thanks for letting us use this xxx, xFiles That string is meant for use in the Arduino environment because of the escape characters like \" and others like \n that means new line. you can try programing windows-key + r to open the run box then Keyboard.Print that command string with the volume label of the external drive your trying to access then enter to run it which in turn opens a cmd.exe with the %DLETTER% environment variable set to the device. //this opens the run box Keyboard.set_modifier(MODIFIERKEY_RIGHT_GUI); Keyboard.set_key1(KEY_R); Keyboard.send_now(); Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now(); delay(1000); //wait 1 second for box to appear Keyboard.print("cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO SET DLETTER=%G"); Keyboard.set_key1(KEY_ENTER); Keyboard.send_now(); delay(25); //delay just in case had some textboxes only respond when the keys where pressed longer than a split second Keyboard.set_key1(0); Keyboard.send_now(); delay(4000); //wait 4 seconds for the cmd window to open Keyboard.print("%DLETTER%somefolder\\script.bat"); //runs script.bat from a drive %DLETTER% usualy e: Quote
PineDominator Posted January 14, 2011 Posted January 14, 2011 O ya I almost forgot if all you want to do is launch a file, replace this part of the code: Keyboard.print("cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO SET DLETTER=%G"); With Keyboard.print("cmd.exe /C FOR /F %I IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO %I"); Keyboard.print("somefolder\\script.bat"); //IE e:somefolder\script.bat makes it a bit faster and less pron to errors in case you start typing before the window opens:) Quote
littleguy1 Posted January 14, 2011 Author Posted January 14, 2011 (edited) O ya I almost forgot if all you want to do is launch a file, replace this part of the code: Keyboard.print("cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO SET DLETTER=%G"); With Keyboard.print("cmd.exe /C FOR /F %I IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO %I"); Keyboard.print("somefolder\\script.bat"); //IE e:somefolder\script.bat makes it a bit faster and less pron to errors in case you start typing before the window opens:) Thank you petertfm! I tried the code below on the run box and it worked. :) For the part you had "DO SET DLETTER=%G" I want to be able to save that variable name to access other files on that same Drive as well but once the command is executed the command line prompt closed. I tried doing something like: Keyboard.print("cmd.exe /C FOR /F %I IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("PNYJUMP"); Keyboard.print("\"') DO %I"); Keyboard.print("folder\\script.bat"); Keyboard.print(" DO move hello.txt %I"); It didn't work... How do you keep that %I value on the command line and keep the command window open? Thank you for sharing your code. littleguy1 Edited January 14, 2011 by littleguy1 Quote
PineDominator Posted January 14, 2011 Posted January 14, 2011 Thank you petertfm! I tried the code below on the run box and it worked. :) For the part you had "DO SET DLETTER=%G" I want to be able to save that variable name to access other files on that same Drive as well but once the command is executed the command line prompt closed. I tried doing something like: Keyboard.print("cmd.exe /C FOR /F %I IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("PNYJUMP"); Keyboard.print("\"') DO %I"); Keyboard.print("folder\\script.bat"); Keyboard.print(" DO move hello.txt %I"); It didn't work... How do you keep that %I value on the command line and keep the command window open? Thank you for sharing your code. littleguy1 Realy? If you stick with: Keyboard.print("cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO SET DLETTER=%G"); The cmd window should stay open and the variable %DLETTER% should stay with that window until closed? maybe your talking about the other string IE "cmd.exe /C" the /C tells the command window to close once the file you tell to open executes. Quote
littleguy1 Posted January 16, 2011 Author Posted January 16, 2011 Realy? If you stick with: Keyboard.print("cmd.exe /K FOR /F %G IN ('wmic logicaldisk WHERE \"DriveType=2\" LIST BRIEF ^| FIND \""); Keyboard.print("place your volume label here"); Keyboard.print("\"') DO SET DLETTER=%G"); The cmd window should stay open and the variable %DLETTER% should stay with that window until closed? maybe your talking about the other string IE "cmd.exe /C" the /C tells the command window to close once the file you tell to open executes. It worked! That is really awesome petertf. Thank you so much!! Just one more question, when you do /K and /F what are those variables supposed to be? Are they key terms in MDOS? Thank you for helping me out. littleguy1 Quote
PineDominator Posted January 18, 2011 Posted January 18, 2011 It worked! That is really awesome petertf. Thank you so much!! Just one more question, when you do /K and /F what are those variables supposed to be? Are they key terms in MDOS? Thank you for helping me out. littleguy1 /K is an option you can set after specifying cmd.exe or cmd http://ss64.com/nt/cmd.html /F is part of the for loop http://ss64.com/nt/ hope you can get allot out of these 2 pages:) This next page helped me with the VBScript'ing stuff in my payloads from arduino_switches_tfmanlib.zip http://ss64.com/vb/ Quote
littleguy1 Posted January 21, 2011 Author Posted January 21, 2011 /K is an option you can set after specifying cmd.exe or cmd http://ss64.com/nt/cmd.html /F is part of the for loop http://ss64.com/nt/ hope you can get allot out of these 2 pages:) This next page helped me with the VBScript'ing stuff in my payloads from arduino_switches_tfmanlib.zip http://ss64.com/vb/ Thank you for showing me sites, petertfm. I learned a lot from your help. :) -littleguy1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.