- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The trouble with Linux is that you always have to deal with incompatible, fragmented versions, whereas there's only one version of Windows to deal with.
Admin
That's why it's going to be called Windows X.
Admin
Blame Microsoft for writing a buggy OS update that breaks their app, probably.
Admin
I guess you learn something new everyday. Today I learned that you use {c | k | tc}sh.exe on *nix.
Other than that - no WTF here, move along.
Admin
Bond: "You expect my code to do operating system independent operations for systems that don't yet exist?" Blofeld: "No mister Bond, I expect it to die"
Admin
Part of using /usr/bin/env is that you can modify the environment for the command being run, a nifty feature that isn't used here.
The other part is that you can better rely on environment variables being set. That usually means the PATH variable in practice; i.e. you can be reasonably sure that the version of "sh" you execute is the same as the one you'd execute if you typed "sh" in the command line.
So using "/usr/bin/env /bin/sh" totally defeats the purpose of "env".
Admin
Admin
So Windows ME uses cmd.exe?
Admin
Admin
Damn. Got beaten to it. I was going to say they needn't worry about Windows 9 coming out because it was already broken from XP up anyway.
Admin
And that is why you use "os.arch" and "os.version" instead of "os.name".
Admin
OK, step 1 complete.
Now that we've determined the server OS, we can use User-Agent to determine the browser capabilities.
Admin
Wrong. os.arch delivers something like "x86" or "sparc", os.version something like "5.1" but you cannot tell if it is Debian Linux or Windows or something else without looking at os.name!
Admin
Just install Cygwin on the offending windows boxes and you should be good to go.
Admin
+2^32 - 1 Inspired.
Admin
And ash, dash, msh, hush, and probably sash, and what about MinGW?
Admin
バカじゃない? The submitter that is. This code might be a WTF. But it's even more of a WTF that it is obviously quite old, and so what really is the point of submitting it at all?
OK, I guess the real WTF is using Java and then wanting to spawn a shell for some reason. Wouldn't you just do everything in Java?
ふck you.
Admin
Very apparently written between Win2K and WinXP.
But there is an Eleventh Commandment: "Thou shalt not try to be clever."
Admin
Admin
As bad as this is, I bet the piece of code after it (that presumably does something with the list of environment variables it finds, or some subset thereof, also attempting to be cross-platform) is an even bigger WTF.
Admin
Java has runtime.exec anyway for this... it does it better, so why? sigh I guess Java is like unix, those who don't understand it are doomed to reinvent it.
Admin
Also, "os.arch" returns the architecture of the JVM, not the actual OS.
Admin
Because may be it did not exist when this code was written? Considering this code does not check for Windows ME (released in Sep 2000) and Windows XP (released in Aug 2001) but checks for Windows 2000 (released in Feb 2000), it is most likely written in middle of 2000. Java Runtime.Exec has been there since 1.3 which was released in middle of 2000.
If you are a developer who uses the beta version of a software or a software whose first production version was released last week/month in production because it has a feature you like, you are bigger WTF than many stories on this site.
Admin
JAVA is like anal sex. It is cross platform, but still it's just not the same..
Admin
+1e6 for posting something other than indignant reactions to trolls pretending to be misogynists.
Admin
It wasn't Blofeld who said that. It was goldfinger.
Admin
There's Win9X, WinNT/2k, and WinVista/7/8, and Microsoft has gone through great pains to ensure that Win9X software still runs on everything up to and including Win8. You can even use command instead of cmd, if you really want. You just can't use it to do New OS things.
As opposed to OSX.1, .2, .3, .4, .5, .6, .7, .8, and .9, each of which is utterly incompatible in numerous ways, with no shims to ensure backward-compatibility.
Or the thirty different flavours of Linux released in the past week.
Admin
"I wonder what they do when windows 9 comes out"
Obviously
if ((osName!="Windows 9")&&(osName.indexOf("Windows 9") > -1))
Admin
Are you sure? When I typed command into Run dialog in W7, it responded with command not found dialog.
CAPTCHA: ingenium - Linux is made of this.
Admin
Admin
On Windows anything, you can just use the ComSpec environment variable. If it's not set, you can try looking for one named SHELL or just fallback to sh.
Admin
The way that is used by lots of Java programs (Ant, for example) to distinguish OSes is the following:
Check File.pathSeparator - if it is ";" it is something Windows, in case of ":" it is something Unix.
To distinguish Win9x/ME from NT family, check value of %OS% environment variable or %COMSPEC% environment variable, and if none found (or Java is too old to have System.getenv), fall back to a hardcoded list of Windows 95/98/ME for os.name (these are the only three Non-NT Windows versions ever supported by Java). To distinguish 95 from 98 or ME, use os.version since older Java versions will return "Windows 95" even on 98 or ME in os.name. Same to distinguish different NT variants (3.1, 3.51, 4.0, 5.0, 5.1 etc).
In case you need to distinguish between different Unix versions (depends on what you need) either have some substring matches for os.name or check for "uname" output.
Or just use http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/SystemUtils.html.
All still quite hacky, but apparently the best solution that currently exists...
Admin
Job security!
Admin
First, you overstate the lack of backwards compatibility in both OSX and Linux. OSX has gone to incredible lengths to retain backwards compatibility, even across CPU architectures (Rosetta and Universal Binaries). There have been a few large breaks- the death of Carbon, the ejection of Java leap to mind. For the most part, applications written according to Apple's best practices in 10.1 still work today in 10.9 (although they probably look like shit and don't benefit from many of the performance enhancements).
Second, backwards compatibility is only good up to a point. When Apple completely cut support for OS9 applications, and later for Carbon and later for PowerPC applications, these were good moves. They ejected some kruft that had accumulated, simplified the architecture of their system, and generally made a better platform.
Microsoft's slavish devotion to making sure applications written in 1995 still run creates all sorts of problems with the WinAPI, or creates bizarre things like the System32 holding 64-bit binaries, and WOW64 holding 32-bit binaries. Worse, Microsoft supports the VBRUN6 runtime, but doesn't support Visual Studio 6- meaning users are running unsupportable applications. Microsoft's own software tools are completely hit or miss as to whether or not they support PowerShell's new conventions (rendering PowerShell nearly useless for all sorts of really useful problems).
At a certain point, technology vendors need the gumption to actually say to their users, "Look, you have to upgrade this shit. I'm sorry, but it's time."
Admin
Admin
And I say that if you break my code, you are the enemy.
Sincerely,
Gene Wirchenko
Admin
Yeah, sh.exe beats anything in the article.
Admin
Even when you did something outside the spec to start with?
Hello? Every dev writing directly to the screen buffer memory address in early versions of DOS is the dev's problem. However M$ allowed you to keep doing it, causing all kinds of stupid memory limits and many years to come.
Yes, do no harm, but you can't allow folks to bypass the rules.
Admin
TRWTF is that they need a shell inside of a shell just to set an environment variable.
Admin
People are the real WTF.
Admin
You're not too far off the mark - that's exactly what businesses do. It's why Microsoft puts such emphasis on backwards compatibility, and even supporting legacy APIs that are not even public for so long (yes, Microsoft is forced to support legacy privacy APIs because even though they're private, someone uses them and getting rid of it means an instant bug report. Nevermind that it's not documented or anything).
It's why Windows Explorer's desktop window is called "Program Manager" (yes, check it out in any program that can show you window titles), among other things. Because there's some out out there that insists on it and will break otherwise.
Apple, OTOH, takes the route of "if it's not in the API documentation, then you take the risk of it breaking the next OS revision". (On iOS, they simply scan API calls to see that they're all legit).
Admin
"I wonder what they'll do when Windows 9 comes out?"
Fail.
Admin
Complain until command.com is brought back in Windows 9.1.
Admin
So is it that hard to create a command.com that pipes commands to cmd.exe?
Admin
Is it "Windows 7" or "Windows NT 6.1"? If Windows 8 is NT 6.2 will Windows 9 be NT 6.3? Or will they abandon this version scheme?
Admin
(Needs to be admin copy.)
Works just fine, in Windows 8.1 anyway.
Admin
Actually, if they somehow failed to find the "latest" source code for this, they could just copy and rename "cmd.exe" as "command.com" and it should still work.
I read that beginning from WinXP, there's no difference in .EXE and .COM file execution in shell. The routine will still check the EXE file signature ("MZ") and call the appropiate execution path accordingly.
Btw, file copy is very common operation in writing GPs so there's really no big deal.
Admin
If you really need to call proper native code, use the Java Native Interface.
If you have written shell scripts and windows batch files for basic processing tasks you can probably translate what they do into java, as it's usually just opening and writing files, manipulating their contents or checking the filesystem for the presence or not of certain files or information.
Otherwise you have an unholy mess of unmaintainable garbage and your only hope is billing by the hour for support or change requests because I don't want to hear what abomination you've cobbled together using the wrong tools for the job.
Admin
No. Java sucks.
Admin
I wonder how much clang will impact upon Windows.