![]() |
|
Problems? Is your data what you think it is? | |
PerlMonks |
Almost cool: removable drive "finder" instead of windows autoplayby Intrepid (Deacon) |
on Jun 02, 2025 at 22:42 UTC ( [id://11165216]=CUFP: print w/replies, xml ) | Need Help?? |
This tool would be cool if it worked flawlessly, and I am shamelessly fishing for help. Rather than Posting in SOPW I'm showing what I've got here so as not to duplicate the same code in two different parts of the Monastery. Windows autoplay will run an application on a USB drive if set up there, but I don't want to. I want to leave autoplay alone so that it just harmlessly opens an explorer window when the drive is mounted. I have one drive (the "Dragon" drive referenced in the code) with a very cool free image program, the FastStone Image Viewer, portable edition, installed on it. When I had it plugged into a USB expansion doohicky I plugged another USB drive directly into a slot on the computer, and to my shock and amazement Windows "bumped" the already-inserted drive to a different volume letter! So I said to myself, "I haven't done any really specific Win32 perl scripting for a while, let me see if I can write code that will check for a drive with specific characteristics then, in this case, exec a command from the perl code to fire up the image viewer." Without knowing the drive letter. What's really strange is that the code doesn't seem to iterate through the array @rmvbl unless I use reverse on it! It's the weirdest thing, I swear this code nearly had me tearing out my hair. Thus all the lines marked "# debugging". To actually run the code you'll have to adapt it to a drive you have on hand and check for a characteristic that Win32::DriveInfo::VolumeInfo() can detect; the vars that receive the retvals of that call are named in a pretty self-explanatory way. EDITI needed a few days to find other ways to mess up and not look at this code, and it came to me. I was returning undef inside the drive iteration loop instead of below it, where it needed to be. One thing to note: the variable $VolumeName will not have a value for every drive. It's actually a property of the filesystem, not of the entire drive. A small distinction but important. Anyhow, I think that MS Windows-formatted USB drives won't have this property (I could be wrong). This drive, I had formatted on Gnu/Linux. One final mystery remains unsolved, and maybe a reader knows something pertaining. The call to exec is never supposed to return if successful, according to Perl's documentation, it is just supposed to completely separate itself from the parent process. When I run this code from a terminal commandline , however, it hangs around until I close the spawned child. Why? Here's the final code, corrected: Jun 02, 2025 at 22:41 UTC A just machine to make big decisions
Back to
Cool Uses for Perl
|
|