Two resources will be helpful: www.seat61.com, which has loads of train information throughout Europe, and www.bahn.de, which gives you train schedule information for most locations in Europe.
The trip is very slow. Expect to spend a full two days on trains.
I don't know how much time you have, but a better bet would be to make some stops along the way. Hungary, Serbia, Romania and Bulgaria are the most likely candidates if you don't want to venture too far out of the way.
Without closely examining maps and schedules, I think your best bet is likely to be through Budapest (you'll have direct connections from Krakow). From Budapest, you could either head through Romania and then down through Bulgaria, or go through Serbia and over through Bulgaria.
Again, not knowing how much time you have, or what you might want to do or see along the way, I'd recommend you check out www.balkanology.com for tons of travel information for the region.
Dave