How do I /give myself a commandblock minecart that already has a command in it?

I want to /give myself a commandblock minecart that already has a command in it. I already tried using the {BlockEntityTag} in the /give command but that didn't work.

/give @p minecraft:command_block_minecart 1 0 {BlockEntityData:{Command:/say hi}}

Anyone know how to do this?


BlockEntityTag is to store potential tile entity data, while minecarts are regular entities. While armor stands and spawn eggs support the usage of the EntityTag compound, minecarts do not.

Your only option would be to rename the minecart and use an external command block to modify minecarts with that name (as the name is transferred as the CustomName on the entity):

/give @p minecraft:command_block_minecart 1 0 {display:{Name:"replace"}}

/entitydata @e[type=MinecartCommandBlock,name=replace] {CustomName:"",Command:"/say hi"}