473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Executing Shell Commands

24
I want to execute group of cmd command from php

for example, i'm going to open an image file from d:\pictures\
and "temp.jpg" is the file's name

In cmd, it's just about :

Expand|Select|Wrap|Line Numbers
  1. cd d:\pictures <enter>
  2. temp.jpg
how 'bout in PHP??

here's what i've tried

Expand|Select|Wrap|Line Numbers
  1. $command="cd d:\pictures";
  2. system($command);
  3. $command="temp.jpg";
  4. system($command);
but it's not workin'...

i really need help for this, THX b4
Jul 24 '08 #1
3 1644
Brosert
57
I think the problem is that cmd (the Windows Command Prompt) knows as much about file tuypes as windows itself (obviously). This means it AUTOMATICALLY decides which program to open the picture with....

PHP deals with the actual command line on the SERVER machine (and quite often a UNIX one) - "temp.jpg" is not actually a command, it is merely a file. You need to decide what you want to do with it.

I'm not really sure that you want to open this file in 'picture viewer' anyway - perhaps if you explained what you are trying to do, someone may be able to suggest a solution. If you are actually using this code across a network, you need to remember that it runs on the server - so it doesn't know what programs you have on the client - and shouldn't assume.
Jul 24 '08 #2
ragonz
24
I think the problem is that cmd (the Windows Command Prompt) knows as much about file tuypes as windows itself (obviously). This means it AUTOMATICALLY decides which program to open the picture with....

PHP deals with the actual command line on the SERVER machine (and quite often a UNIX one) - "temp.jpg" is not actually a command, it is merely a file. You need to decide what you want to do with it.

I'm not really sure that you want to open this file in 'picture viewer' anyway - perhaps if you explained what you are trying to do, someone may be able to suggest a solution. If you are actually using this code across a network, you need to remember that it runs on the server - so it doesn't know what programs you have on the client - and shouldn't assume.
here's my problem

i want to load data by using sql loader into oracle table.

The default directory for sqlldr is c:\documents and settings\user
while the data is in inetpub folder. The data come from uploading process in PHP, i tried to copy the upload files into the default directory for the sql loader but, it didn't work. and the uploaded files are in the inetpub folder.

It'll be easier if i could copy the uploaded files into sqlldr directory, coz i don't need to (change dir [cd ] in cmd line) just execute the command. But, since they're not in the right folder, i need to chage the dir first and then execute the command (i have to execute it when it's in the right dir). Those are 2 different commands, but related one another.

So..?? how 'bout it??
Thx.
Jul 24 '08 #3
Brosert
57
Assuming the PHP is running on a UNIX server (which is quite likely, I think), you can use:
Expand|Select|Wrap|Line Numbers
  1. cp {fileoriginal} {filenew}
to copy a file
or
Expand|Select|Wrap|Line Numbers
  1. mv {currentFile} {FutureFile} 
to move the file

This should be able to be executed in PHP using something like:
Expand|Select|Wrap|Line Numbers
  1. system('mv ~/temp.jpg ~/otherPath/temp.jpg' );
  2.  
Note: I assume that executing system commands has not been disabled on the server you are running the PHP on - you will get a reasonably clear message if it has been disabled....
Jul 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Falk Schneider | last post by:
I wrote a PHP shell script under Linux which puts all existing PS-Files within a directory into a list and should then start a single Ghostview window for each file. Sounds simple, but it's not: ...
6
by: twsnnva | last post by:
Could anyone give me an example (code) of a simple program with a button that when clicked executes a linux shell or windows dos command like "ifconfig" or "ipconfig" and prints the output...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
0
by: Bruceneedshelp | last post by:
My application starts logging and executes shell commands on startup. The application runs fine, except when it executes at boot time. In other words when I make it a "startup" application on my...
2
by: Mark | last post by:
hi, i've written a c++ program that converts one file type to another via two arguments (the input and output filenames). i want to execute this on my server, using something like ...
3
by: Ara Kooser | last post by:
Hello all, I hope I am posting this correctly. I am running Python 2.4.2 on Slackware 11.0 using IDLE. I am in the process of learning python so I am writing a text adventure game using...
10
by: Kentor | last post by:
I know I can use the system function to execute commands, but I need to pass parameters to it and it doesn't want to accept them... is there a way to do system("mv %s temp123", myvar) ? or maybe...
1
by: Riccardo Maria Bianchi | last post by:
Hello! :) I'm trying to run shell commands both with os.system() and subprocess.Popen() class. But I can't run aliases or function defined in my .bashrc file, like in the login interactive...
1
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.