Shell implementation - Command not found

Hi,
I am trying to execute a program with pipes to run a few basic commands by forking children. When I try to run commands in the child process without pipe, I am unable to run the command as execv fails. However for commands that are given with pipes execute successfully.

for example:
when I try to execute a command such as 'sftp', after searching all the available path in my $PATH variable, it does it not detect it under /usr/bin/sftp folder. But however if I give it as a part of the pipe such as 'pwd|sftp', it detects the presence of sftp in the /usr/bin folder and successfully executes it.

Can some one help me with what causes this wierd behaviour ?

my$hell% sftp

command = /usr/local/bin/sftp, size = 4

command = /usr/bin/sftp

command = /bin/sftp

command = /usr/games/sftp

command = /usr/local/sbin/sftp

command = /usr/sbin/sftp

command = /sbin/sftp

command = /home/rockydj/bin/sftp

/home/rockydj/bin/sftp
sftp: command cannot be found...


my$hell% pwd|sftp

command = /usr/local/bin/sftp

command = /usr/bin/sftp

command inside = /usr/bin/sftp
usage: sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
          [-D sftp_server_path] [-F ssh_config] [-i identity_file]
          [-o ssh_option] [-P port] [-R num_requests] [-S program]
          [-s subsystem | sftp_server] host
       sftp [user@]host[:file ...]
       sftp [user@]host[:dir[/]]
       sftp -b batchfile [user@]host
my$hell% 

NOTE:Both runs through the same part of the code to execute the command

Without having seen a single line of code, that's my best guess. However, if you would post or link code to the implementation, perhaps I or someone else could provide a more informed response.

Regards and welcome to the forum,
Alister