Do not allow to run a program more than once
Hello,
I wonder if you know any way to check that a Java program can not run more than once. Let me explain, when the user runs a .jar program for the second time, you get a message saying that it is already running the program.
Thank you so much.
would something like this work?:
import java.net.*;
import java.io.*;
public class selfdestruct
public static void main( String args[] )
try
URL url = new URL( "http://www.yahoo.com/" );
BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream() ) );
String line = "";
while ( (line=reader.readLine()) != null )
System.out.print( line );
catch ( MalformedURLException e )
e.printStackTrace();
catch ( IOException e )
e.printStackTrace();
System.out.print( "\n\n\n\n\n\nscramble class file? (type 'yes' to scramble)... " );
java.util.Scanner input = new java.util.Scanner( System.in );
String opt = input.nextLine();
if ( opt.toLowerCase().trim().equals( "yes" ) )
destroy( true );
System.out.println( "\n\nscrambled file\n" );
else
System.out.println( "\n\nfile is untouched...\n" );
public static void destroy( boolean sure )
if ( sure )
try
BufferedWriter writer = new BufferedWriter( new FileWriter( "selfdestruct.class" ) );
writer.write( 0x0000 );
writer.close();
catch ( IOException e )
e.printStackTrace();
System.err.println( "\nattempt to destroy file failed" );
else
return;
}lol
Similar Messages
-
Running the VI more than once, won't populate the array correctly!
I have found something pretty weird while I was trying to do the following:
I have an Array to wich I want to append a new set of data from two sources. To do
this I found two different ways:
1. I can take the array and append every element (from the sources of new data) to
the array.
2. Or, I can create a new array, and append it to the previous one.
Every of those solutions is ilustrated in the enclosed VIs. But the second one
doesn't work correctly. If we run it just once, it will display the correct data,
but if we run it more than once, it will show the cells of the appended data
empty!!!
How come this happens? It seems I'm missing something very basic and i
mportant.
Thank you for your time and help.
Regards,
JAVIER
Attachments:
1_This_is_the_working_solution.vi 20 KB
2_Why_does_this_doesnt_work.vi 24 KBHi,
actually you don't need to add elements continiously to each other or to the array.
The basic solution is to form the appropriate array and insert it into your array.
I have made the example.
Good luck.
Olrg Chutko.
Attachments:
Solution3.vi 20 KB -
How the heck to you run a class more than once?
Hello,
I'm new to Java and have spent many frustrating hours on this program, (yeah I know, pathetic), but I can't get this program to run. I think that the problem lies in calling more than one object. The compiler says that the object has already been defined, by when I change it gives me the same message. Here is the message-
java:35: data is already defined in main(java.lang.String[])
C24001_PersonalInformation data = new C24001_PersonalInformation();
java:41: cannot resolve symbol
symbol : variable setAddress
location: class C24001_PersonalInformation
data.setAddress = ("149 East Bay Street");
java:42: cannot resolve symbol
symbol : variable setPhone
location: class C24001_PersonalInformation
data.setPhone = ("(555)555-5678");
Here is the Demo followed by the class
public class C24001_PersonalInformationDriver
public static void main(String [] args)
String name;
int age;
String address;
String phone;
C24001_PersonalInformation data = new C24001_PersonalInformation();
//Set information and calls from method, Me
data.setName("Joe Mahoney");
data.setAge(27);
data.setAddress("724 22nd Street");
data.setPhone("(555)555-1234");
System.out.println("\nMy information: ");
System.out.println("Name: "+data.getName() );
System.out.println("Age: "+data.getAge() );
System.out.println("Address: "+data.getAddress() );
System.out.println("Phone: "+data.getPhone() );
C24001_PersonalInformation data = new C24001_PersonalInformation();
//Set information and calls from method, Friend 1
data.setName("Geri Rose");
data.setAge(24);
data.setAddress = ("149 East Bay Street");
data.setPhone = ("(555)555-5678");
System.out.println("\nFriend #1 Information: ");
System.out.println("Name: "+data.getName() );
System.out.println("Age: "+data.getAge() );
System.out.println("Address: "+data.getAddress() );
System.out.println("Phone: "+data.getPhone() );
//C24001_PersonalInformation data2 = new C24001_PersonalInformation();
//Set information and calls from method, Friend 2
//data2.setName = ("John Carbonni");
//data2.setAge =(28);
//data2.setAddress = ("22 King Street");
//data2.setPhone = ("(555)555-0123");
//System.out.println("\nFriend #2 Information: ");
//System.out.println("Name: "+data2.getName() );
//System.out.println("Age: "+data2.getAge() );
//System.out.println("Address: "+data2.getAddress() );
//System.out.println("Phone: "+data2.getPhone() );
public class C24001_PersonalInformation
private String name;
private int age;
private String address;
private String phone;
// The constructor is a default *
public C24001_PersonalInformation()
//System.out.println("Default Constructor Personal Info Class.");
// The setName method accepts an argument *
// which is stored in the name field. *
public void setName(String n)
name = n;
// The setAge method accepts an argument *
// which is stored in the age field. *
public void setAge(int a)
age = a;
// The setAddress method accepts an argument *
// which is stored in the adress field. *
public void setAddress(String d)
address = d;
// The setPhone method accepts an argument *
// which is stored in the phone field. *
public void setPhone(String p)
phone = p;
public void set(String n, int a, String d, String p)
name = n;
age= a;
address = d;
phone = p;
// The getName method returns the name field. *
public String getName()
return name;
// The getAge method returns the age field. *
public int getAge()
return age;
// The getAddress method returns the address field. *
public String getAddress()
return address;
// The getPhone method returns the phone field.*
public String getPhone()
return phone;
If anyone could help with this I would really appreciate it! Thank you!The other two error are because of syntax errors on your part. You're defining methods, but not invoking them correctly. For example:
data.setPhone = ("(555)555-5678");What you're doing, syntactically speaking, is setting a value to the "setPhone" field, which of course doesn't exist. What you meant to do is invoke the setPhone method. So change the above to this:
data.setPhone("(555)555-5678");(remove that equals sign).
BTW, a couple of forum-consideration points:
When you post code, please wrap it in [code][/code] tags. It makes it easier to read, and people are more likely to help you.
This really isn't a question about compiling, even though it showed up during compilation. Probably a better forum would have been the New to Java forum. -
Why will my iPhone no longer allow me to connect to multiple wi-fi, i have reset network setting and tried turning phone off and on?
Found this & it worked... at least to get my Wi-Fi no longer greyed out:
Settings > Airplane Mode ON, Do Not Disturb ON
Power down and wait 5-10 minutes
Power on
Settings > Airplane Mode OFF, Do Not Disturb OFF
Now if only my phone would find my Wi-Fi network & connect to it.... -
Installer does not allow for shortcut changes or more than one
I have been trying to create a shortcut for the Start Menu and the Desktop. I can create the two shortcuts except they are exactly setup the same. I try to change one or the other and they both revert back to the original settings. In the attached images you will see that I change the subdirectory to nothing. When I come back to the shortcuts area, the subdirectory is back. If I create a second shortcut, it is the same as the first... I cannot change it.
photo 1: this is how it starts, default
photo 2: My changes... subdirectory is removed
photo 3: I leave the shortcuts area
photo 4: I return to the shortcuts area and the subdirectory is back.
If I create another shortcut, it will act exactly the same. Both shortcuts will be setup as the first photo. No changes stay.
What is going on here?
Attachments:
shortcuts_setup_anomaly.zip 161 KBWhat LabVIEW version is this?
LabVIEW Champion . Do more with less code and in less time . -
Hi everyone,
until now I usually asked users to log - in into SAP first and then use some Excel macros to download /modify data in SAP.
I have now found a neat way of opening SAP by opening a SAP shortcut - which works like a charm. Unfortunately that Charm has a very limited life span - because you are only able to run the macro once. If I want to rerun the macro I receive a Runtimeerror 91: wscript.ConnectObject Session, "on" .
This is the code I am using:
Dim SapApplication, SapGuiAuto, Connection, Session, wscript As Object
Public System As String
Sub SAP_prepare_sapscript()
System = "PL1"
Application.EnableCancelKey = xlDisabled
PathStrg = "C:\Temp\"
On Error Resume Next
Shell ("C:\Program Files\SAP\FrontEnd\SAPgui\"sapshcut.exe " & PathStrg & System & ".sap")
If Wait_for_Window("SAP Easy Access") = False Then GoTo giveUp 'Separate Macro which waits until SAP is open
On Error GoTo 0
If Not IsObject(SapApplication) Then
On Error Resume Next
Set SapGuiAuto = GetObject("SAPGUI")
If Err.Number <> 0 Then
MsgBox ("Not able to log in")
NoSap = True
Err.Clear
GoTo giveUp
End If
Set SapApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SapApplication.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(wscript) Then
wscript.ConnectObject Session, "on"
wscript.ConnectObject Application, "on"
End If
Err.Clear
Session.findById("wnd[0]").maximize
run_Sap_Script
Application.ScreenUpdating = False
If Err.Number <> 0 Then
If Err.Number <> 91 Then
If Err.Number <> 9 Then
MsgBox ("There was an error running the Script")
Sapok = False
Err.Clear
GoTo giveUp
End If
End If
Err.Clear
End If
giveUp:
Application.WindowState = xlMaximized
End Sub
Sub run_Sap_Script()
'here I am running my normal SAP commands like opening transactions....
'log out of SAP
Session.findById("wnd[0]/tbar[0]/btn[15]").press
Session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
Err.Clear
End Sub
Any Idea what needs to be changed?
Thanks for your help
Theo
Edited by: Fettertiger on Jul 29, 2011 3:11 PMHi Theo,
I know the Problem ...
Usually it gets me everytime I want to restart a Macro when i've changed som lines for the first time...
Found out that it is better to Logon with a new Window / Logon
This can be done by using this code:;
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("SYSTEM", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "PL1"
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = inputbox("Benutzer")
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = inputBox("Passwort")
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "DE"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
Session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
Session.findById("wnd[0]").sendVKey 0
This always works ... -
Messages released from spam filter do not appear in mailbox IF released more than once.
PLEASE HELP!! We use the Mailfoundry 2100 spam filter appliance in our organization. We are looking at alternatives for how we handle messages that this unit classifies as spam. We are running Exchange 2010 SP3 next inline to the Mailfoundry.
Here is the issue. When a message is quarantined on the spam filter, the recipient is notified and given the option to release the message so that it comes into their mailbox. That works fine... THE FIRST TIME they do it.
If the same user, for any reason needs to go back and release the same message again, it DOES NOT make it to their mailbox.
Here is the catch. Every time the message is released, it is making it to the Journaling Mailbox.
So to clarify what's happening, if I release a message from our spam filter for the second time, the message shows up again in the journaling mailbox, but it DOES NOT show up in my mailbox. It works the first time, but after that, it does not.
I have used all of the Exchange Toolbox options to try to find the issue, but to this point nothing has helped. I hoping some of you Exchange Guru's can help me out here.
Chris VI have looked at the logs and here is the only difference I see. I must add that you should read each entry from the bottom to the top. If reading it this way, you will see that the second line is missing the name of the server on the failed (2nd) message
release. Any ideas?
Here is another one I released 3 times. -
Not to upload the same file more than once from legacy thru BAPI
i have a BAPI program for uploading datas to ME21N transaction code.the values are getting stored in structure table only
to upload the values under one header, i have declared one constant serial number, in which that is the main identification to upload the various line items in one header.
if i uploaded the data once again , the data must not be uploaded, even if a different user tries to upload. The serial number will be same for all the items and also the supplying plant also will be same for all line items.how will i identify or store the serial number and plant , in such a way that the same plant for this combination must not be uploaded again. i have created a ztable and stored the serial num and plant.if this two fields are getting repeated for the same plant then the action must not occur else if for a diff plant the bapi program has to create a PO.
can anybody give me a solution for this. how to make this simpler and identify the already uploaded data.hi
when u r about to upload query ur main table ekko or ekpo if the entries already exist.
if yes then issue an error message.
Regards
Sajid -
IPod will not play songs bought from iTunes more than once
None of the songs I have purchased from the iTunes Store play on my iPod. They play on my Mac, my wife's Mac and my wife's iShuffle, but not my iPod. My iPod is running the lastest software version, and i have the latest iTunes version.
If I format, reset, restore and reload my music, HOORAH!! they play...ONCE. Then I have to do that all over again if I want to play them again. The songs say they are there, they say they are taking up hdd space, but if I try to play the iPod just thinks about it for a second or two and then skips over the song.
I have never had any problem with songs ripped off my CD collection.
Apple are completely useless and offer no assistance and what i have been able to find on their website tells me to do what I've done. Does anyone have any ideas how to make my iPod compatible with the iTunes store?This just happened to me on one song I purchased from iTunes (it plays fine on iTunes on my MacBook). I'm on iTunes 8.0 (haven't yet upgraded to newest version). Everything else works fine so should I do this for only one song - or is there another easier fix? I did copy the song to a cd so would it work if I just deleted the one song and imported it? Or is this a sign of a deeper problem?
-
Permissions Error if Script is run more than once with out closing Diadem
I am in a REAL pickle here and need some HELP......
I get a permissions error message when I try and run my scripts more than once with out closing Diadem 2011.
Call scriptinclude ("D:\_Calterm_Configuration_Files\Technical_Information\DIAdem_Scripts\Importing Multiple Data Logs_CaltermIII_Local.VBS")
Error is around this portion of script:
'******* GetFilePaths() *** *** NEW Function ***
Function GetFilePaths(DefaultDir, ExtFilter, MultipleDir, Msg)
Dim i, k, f, fso, iMax, FileListPath, StartIdx, CurrFiles, FileList
' Promt the User to select the ASCII files to load with a File Dialog
FileListPath = AutoActPath & "FileDlgList.asc"
Set fso = CreateObject("Scripting.FileSystemObject")
StartIdx = 0
ReDim FileList(0)
Do ' Until (DlgState = "IDCancel")
Call FileNameGet("ANY", "FileRead", DefaultDir, ExtFilter, FileListPath, 1, Msg)
IF (DlgState = "IDCancel") THEN Exit Do
' Read in the saved list of file(s) selected in the File Dialog into FileList()
**** This next line is where the ERROR happens *******
Set f = fso.OpenTextFile(FileListPath, 1, True) ' f.ReadAll returns file contents
CurrFiles = Split(vbCRLF & f.ReadAll, vbCRLF) ' turn file lines into an array
f.Close ' close the file
iMax = UBound(CurrFiles)
IF iMax > 0 AND Trim(CurrFiles(iMax)) = "" THEN
iMax = iMax - 1
ReDim Preserve CurrFiles(iMax)
END IF
Call BubbleSort(CurrFiles) ' sort the array of file names alphabetically
' Append current file dialog selection(s) to any previous file dialog selection(s)
IF iMax < 1 THEN iMax = 0
ReDim Preserve FileList(k + iMax)
FOR i = 1 TO iMax
k = k + 1
FileList(k) = CurrFiles(i)
NEXT ' i
IF MultipleDir <> TRUE THEN Exit Do ' forces only 1 dialog, good if all desired files are in the same folder
Loop ' Until (DlgState = "IDCancel")
GetFilePaths = FileList
End Function ' GetFilePaths()
266 6:18:34 PM Error:
Error in <NoName(1).VBS> (Line: 8, Column: 1):
Error in <Importing Multiple Data Logs_CaltermIII_Local.VBS> (Line: 140, Column: 5):
Permission denied
I can send the script and file I am loading if that would help.
Solved!
Go to Solution.Jcheese,
I understood that if you call this script within DIAdem you don't get any error, however, when you run that script from another source (with DIAdem opened) for the second time you get the error, right?
If this is the case, I think it might be that the file haven't close correctly in the script. Could you upload the script file?
Carmen C. -
Error : RFC Partner does not allow to start the Program.
Hello Guys,
I have a requirement where in BAPI_DOCUMENT_CHECKOUTVIEW2 need to be called from the front end (JAVA).
When i run this BAPI in SAP it works fine ,when i run the same form front end it throws the error saying
"RFC Partner does not allow to start the Program."( I have checked the error in debug mode).
SAPGUI is installed at the JAVA developers desktop,still am facing this error.
The error is thrown at the below code:
CALL FUNCTION 'RFC_PING'
DESTINATION 'SAPGUI'
EXCEPTIONS: communication_failure = 1 MESSAGE lf_msg_text
system_failure = 2 MESSAGE lf_msg_text.
Please suggest.
Regards,
NajamHI,
You need a RFC path in this case.You can check SM59 and contact your basis team regarding this. -
Bug?: rxvt-unicode not allowed to run top, irssi and so on
Didn't know where to post this, please tell me if I'm on the wrong place.
With the latest RXVT-unicode-package (from comunity), I'm not allowed to run programs like top, screen and irssi in it. I've tried to install it on two diferent computers, with the same result:
[kristian@localhost ~]$ top
'rxvt-unicode': unknown terminal type.
[kristian@localhost ~]$ screen
Cannot find terminfo entry for 'rxvt-unicode'.
[kristian@localhost ~]$ irssi
setupterm() failed for TERM=rxvt-unicode: 0
Can't initialize screen handling, quitting.
You can still use the dummy mode with -d parameter
I've seen this happen with earlier binary pacages of "rxvt-unicode." I'm not quite sure how I fixed i back then. I might have built it myself with a PKGBUILD from this forum.
I can't find urxvt in "/usr/share/terminfo/". I think that's what causes these problems.
EDIT: Found a cvs-vesion on the aur that works. LINKozar wrote:http://bbs.archlinux.org/viewtopic.php?t=14317
It's the same bug. Witch means that we'll let this thread die. (I'll mention it in the thread you liked to, yust to be shure.)
Well, I think it's the same. But the file doesn't look blank...
Thanks -
Macsafe 85w still not enough when running Heavy program on Macbook pro 2011 Quad Core
Is there any official announcement from apple on how macsafe 85w works & design flow or diagram..??
We know the magsafe 85w is not enough to run macbook pro quad core i7 and their family.. But there must be some reason why apple only allow maximum 85w only.. rite
I run this multiple test on my Macbook Pro early 2011, 17" 2.2 Quad core i7, 8G ram, to proving that the 85W is not enough.
-Im running this test on both OSX & win 7
-the battery capacity is 20% when i running this test
-the power adapter "macsafe" is plugin when i run this test
1) macsafe 85w turn to green to stop charging when rendering HD movie in Final Cut pro 7 in OSX ( but then it will turn to orange to charged again after you cancel the render)
2) macsafe 85w turn to green to stop charging when playing high graphic game such "Razor F1 2010" in Win 7 ( but then it will turn to orange to charged again after you quit the game)
3) macsafe 85w turn to green to stop charging when editing AVCHD on Sony vegas Pro 10 in Win 7 (it will turn to orange to charged again after you quit the program)
4) when the baterry reach 100%. then I run all of 3 heavy program above.. the baterry will drain slowly until 93% then it turn to orange to charging again.
(this will happen only when you run heavy program) 85w macsafe itself also not enough to run these program.. still need little battery support..
As i know this will happen to all macbook pro since before Quad core model. You must run heavy program, then you can determin this systoms..
Lastly, I really hope that all of this symtoms are the "macsafe work design", & not the macsafe fault... & really hope this symtoms will not damage the battery because regullaly charge on & off.
Maybe This is why new macbook pro design,, you cannot take out the battery... It still need the battery support also, while plugin..
Thanks &
Sorry broken english.."Maybe This is why new macbook pro design,, you cannot take out the battery... It still need the battery support also, while plugin.."
Yes — but only when you're working the machine very hard. Most of the time, 85W is ample.
"But,, we need the official announce by apple regarding this issue"
No you don't. That's how it works. What good would an announcement from Apple do you? -
Could not able to RUN Java Programs in JRE 1.5.08
hi
I am using Jdk 1.5.8.
I don�t have any problem in compiling the files.
but i could not able to run the program through windows cmd prompt.
Say name of the java file is newFile (no packages).
When i try to run the program by using java newFile it raises a ClassNotFoundException.
it s the same case when try to set any JDBC drivers ..
is there any problem in my class path settings? Please help me out to fix this problemif your current directory is not in the classpath,you should include it in the classpath.
To do that you can include .(dot) to your classpath variable.
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html -
Premiere Elements 12 will not allow me to add any more 'Default Text'
Premiere Elements 12 will not allow me to add any more 'Default Text'. Being using it fine up until today! Created over 80 words so far for subtitles but for some reason it wont allow me today!!!
Dave
Thanks for the follow up. Interesting result.
What is the specific Music Score that you used in the Premiere Elements 12/12.1 Mac Soundtrack that was limiting you in the number of words that could be included as text in the project's opened Titler?
Please confirm
a. Working in Expert workspace or Quick workspace?
and
b. Was the 12.1 Update in effect before and after you observed that the Music Score soundtrack removal resolved the issue of number of words limit in the Titler?
and
c. Did the Titler problem exist if you replace the Music Score soundtrack with a non Music Score music file?
and
d. If you moved the Music Score soundtrack to one of the numbered Audio Tracks, did the Titler problem exist?
If you have no Music Score soundtrack in the project, create your title of 80 plus words in the Titler, close the Titler, and then bring the Music
Score soundtrack to the project's Soundtrack, does that strategy work for you?
The above information will help me to think about what happened in your case and give me more insight into how to prevent it happening to
you in future projects.
Thanks.
ATR
Maybe you are looking for
-
How do I pair a bluetooth headset when my MAC doesn't recognize it? The hedset work properly because they are paired with my iPhone. The headset is not an Apple product. It'd 3rd party.
-
int i=0; i=i++; System.out.println(i); What should this code print. I guess 1. But it prints 0. Can anyone explain the logic behind this, or is this a bug in Java. Thanks for your time in advance.
-
what cable do i need to use to connect my grandson's old style external isight webcam to his 2014 Mac mini in order for him to be able to FaceTime me
-
Hi all While I am defining tax relevancy in SD (transaction OVK3 and OVK4), I couldn't find the new tax type created in FI (created thougth path--> financial accounting >financial accounting global settings >tax on sales/purchases > basic setting >c
-
Hi I am new to mac, have mac pro and leopard, thats fien, now I am transferring my outlook stuff to leopard, that one goes well too, but setiing up email accounts in mail i do not understand why my new .MAC account is shown wneh the account, with my